Professional Documents
Culture Documents
Outline
Using arrays in SAS
Recoding variables, computing new variable, collapsing over variables Identify patterns across variables using arrays Reshaping data format btw long and wide using arrays
**recoding variables; DATA recode_missing recode_missing; ; set faminc; faminc; array inc[12] faminc1 - faminc12; * do i = 1 to 12; * if inc[i inc[i]=]=-999 then inc[i inc[i]=.; end; drop i; RUN;
FIRST. : indicates the first observation for PROC SORT data=long_array data=long_array; long_array; each unique value of by-variable; by famid; famid; RUN; LAST. : indicates the last observation for each DATA wide_array; wide_array; unique value of by-variable. set long_array; long_array; by famid; famid; retain faminc1faminc1-faminc12; array Afaminc(12) Afaminc(12) faminc1faminc1-faminc12; if first.famid then do; do i = 1 to 12; Afaminc[ Afaminc[i] = .; end; end; Afaminc(month) Afaminc(month) = faminc; faminc; if last.famid then output; drop month faminc i; RUN;
Note: When using first.var_name or last.var_name we must first sort the data set on the variable of interest. Moreover, in the data step we must always precede first.var_name or last.var_name with a by var_name statement.
Define a macro variable by using %let statement; Dispaly macro variable values as text in the SAS log by using %put statement;
*using a macro variable; *double quotes vs single quotes; quotes; title "the date is &sysdate9 and today is &sysday &sysday"; sysday"; title2 'the date is &sysdate9 and today is &sysday &sysday'; sysday'; PROC MEANS data=&data; var population &indvar &indvar; indvar; RUN; PROC REG data=&data; model Population=&indvar Population=&indvar; indvar; RUN; QUIT; *displaying text in log; %put &sysdate9 is the date on which you invoked SAS.; *displaying SAS system macro variables; %put _automatic_;
**%eval **%eval is only for integer evaluation; %let tot = %eval %eval(&k eval(&k + 1.234); %let tot = %sysevalf(&k + 1.234); %put &tot; %put;
Step 5: Make the program into a Macro definition Step 6: Use parameters in the Macro and specify the parameters when the Macro is called
Start the macro definition with %MACRO macro_name; End the macro with %MEND macro_name; To invoke the macro definition, use %macro_name Note: there is no semicolon at the end of macro definition when the macro is called.
S (t ) = P (T t ) = 1 F (t )
f (t ) h (t ) = S (t ) => d log( S (t )) = h (t ) dt
Hazard function:
j |t ( j ) t
(1
dj nj
Cox Regression:
h i ( t ) = h 0 ( t ) exp( T x i ) => S i ( t ) = S 0 ( t ) exp( => log( H i ( t )) = log H 0 ( t ) + T x i
T xi )
h0 (t )
PROC LIEFETEST <DATA=SAS-data-set> ; TIME time_var*cencor_var(list) ; STRATA categorical_varlist; RUN; PROC PHREG <DATA=SAS-data-set> ; MODEL tvar*cvar(list) =predictors; <program statements> TEST var_list; STRATA strata_varlist; BASELINE OUT=<> COVARIATES=<>; RUN;
custcat3 = 1;
custcat4 = 0;
PROC PHREG data=sas3.telco; model tenure*churn(0)=marital address employ custcat2 custcat3 custcat4; custcat2=(custcat custcat2=(custcat=2); custcat=2); custcat3=(custcat custcat3=(custcat=3); custcat=3); custcat4=(custcat custcat4=(custcat=4); custcat=4); baseline out=surv out=surv covariates=cov_pat covariates=cov_pat survival=surv survival=surv / nomean; nomean; RUN; goptions reset=all; symbol c=red v=triangle h=.8 i=stepjll; stepjll; axis1 label=(a=90 'Survivorship function'); PROC GPLOT data=surv data=surv; surv; plot surv*tenure=marital surv*tenure=marital / vaxis=axis1; vaxis=axis1; RUN; QUIT;
0 j = 00 + 01Z j + u0 j 1 j = 10 + 11Z j + u1 j
11Z j X ij + u0 j + u1 j X ij + rij
STATEMENT
interpretations produces asymptotic standard errors and Wald Z-tests for the covariance parameter estimates. Identifies categorical variables. prints the fixed effects estimates in the output. identifies the elements of the model to be specified as random effects Identifies grouping variable
goptions reset=all; symbol1 v=none i=join c=red ; symbol2 v=none i=join c=blue ; axis1 order=(order=(-4 to 3 by 1) minor=none label=("Group Centered SES"); axis2 order=(0 to 22 by 2) minor=none label=(a=90 "Math Achievement Score"); PROC GPLOT data = toplot; toplot; by strata; plot predicted*cses predicted*cses = sector / vaxis = axis2 haxis = axis1; RUN; QUIT;
PROC TSCSREG <DATA=SAS-data-set> ; ID cross_sectional_id_var time_series_id_vari; MODEL depedent_var = regressors / options; RUN;
Thanks!
CAC statistical WIKI page:
http://research2.smu.edu.sg/CAC/StatisticalComputing/Wiki/SAS.aspx