Manipulating Variables in Sas

12
MANIPULATING SAS DATASETS

description

variables to manipulate in sas

Transcript of Manipulating Variables in Sas

CREATING VARIABLES IN SAS

MANIPULATING SAS DATASETSOUTLINECreating New SAS datasetsCreating/Recoding variables in SASBasic SAS Procedures2Creating New SAS datasets

It is always advisable to create a new data set from your existing dataset before you begin any form of manipulationUsing a Data stepSub-setting variables (keep=, Drop=)Sub-setting Observations(obs=, firstobs=)Conditional statements(If and where, where=)Creating/recoding variables in SASThe Assignment StatementIf-Then statementsUsing arraysUsing DO loops(topic on its own)Assigning User defined Formats

The Assignment StatementUsed to create new variables or transform existing variablesGeneral Syntax[New Variable]=Expression;New Variable represents the name of the new variable you intend to create Expressions consists of one or more constants(character or numeric), variables, functions and operatorsThe Assignment StatementExampleGrand_Total= price*number_Yatch;Educ_New= 5- Educ;

SAS Functions and OperatorsFunctions are built in programs in SAS used to perform computations on character and numeric values.General SyntaxVariable=Function-name(argument1,argument2,.);Operators are mathematical, logical, or character operation or manipulation that combines, compares, or transforms numeric or character values. Eg AND OR > < =IF-THEN/ELSE statementsUsed for recoding existing variablesUsed for creating new variables from existing variablesGeneral SyntaxIf existingvariable then newvariable;Else newvariable;Assigning User-defined formatsAside displaying your results in a meaningful way, it can be used for categorizing a continuous variable and recoding variablesFirst step is to create the user defined format using the PROC FORMATGeneral Syntax Proc Format; value formatname assignment;Run;Second step is to assign the created format to the variable using a format statement in the data step or procedure step.General SyntaxFormat variable formatname.;BASIC SAS PROCEDURESPrint Procedure (PROC PRINT)Means Procedure(PROC MEANS)Sort Procedure(PROC SORT)Frequency Procedure(PROC FREQ)Univariate Procedure(PROC UNIVARIATE)Correlation Procedure(PROC CORR)

THANKS FOR LISTENING