A. Usage
- Extract sub-string from a string in Macro
B. Code
%let newvar = %substr(&var., 3, %length(&var.)-2); *Newvar is trimming the first 2 characters off the var;
A journey of a thousand miles begins with the first step.
A. Usage
B. Code
%let newvar = %substr(&var., 3, %length(&var.)-2); *Newvar is trimming the first 2 characters off the var;
A. Multiple Titles/Footnotes
title title2 title3 footnote footnote2 footnote3
B. Alignment: default is center.
justify=
C. Font
f=
D.Bold/Italic
bold italic
E. Font size
h=
F. Example
title1 f='Calibri' h=14pt 'Report Title'; title2 "Report Title1"; title3 "Report Title2"; footnote "Prepared by First Last on %sysfunc(date(),worddate.)"; footnote2 justify=left h=8pt bold "Note:"; footnote3 justify=left h=8pt italic "footnote3";
A. Extract Month, Year information from DateTime.
date=datepart(datetime); year=year(date); month=month(date);
B. Date Value for Date Comparison
C. Age calculation
age = intck('Year', birth, "01JUL&yr."D, 'C');
A. Different Standard Errors
B. Estimate function in the GLM procedure
A. Reference
B. Data
data BlockDesign; input block a b y @@; datalines; 1 1 1 56 1 1 2 41 1 2 1 50 1 2 2 36 1 3 1 39 1 3 2 35 2 1 1 30 2 1 2 25 2 2 1 36 2 2 2 28 2 3 1 33 2 3 2 30 3 1 1 32 3 1 2 24 3 2 1 31 3 2 2 27 3 3 1 15 3 3 2 19 4 1 1 30 4 1 2 25 4 2 1 35 4 2 2 30 4 3 1 17 4 3 2 18 ; run;
C. Normality Check
%macro uni (data, var); Title "Check Nomality and Distribution - &var. in &data."; proc univariate data = &data. ; var &var. ; histogram / cfill = gray; run; proc univariate data = &data. normal plot; var &var.; qqplot &var. / normal (mu=est sigma =est); run; %mend uni; %uni(blockdesign, y);
D. Output
A. Reference
B. Purpose
C. SAS code
proc reg data = cars; model msrp = enginesize cylinders horsepower / tol vif collinoint; run; quit;
D. Notes
E. SAS Output
F. Interpretation
A. Pearson Correlation: Between continuous variable and continuous variable.
%macro corr (in, year); Title "Check Correlation - &in. group"; proc corr data= &in._&year. outp=corr_&in._&year. plot=(matrix scatterplot); var exper salary ; run; %mend corr;
B. Polyserial Correlation: Between continuous variable and categorical variable.
%macro corr (in, year); ods output polyserialCorr=corr_polys_&in._&year. ; Title "Check Polyserial Correlation - &in. group"; proc corr data= &in._&year. pearson polyserial; with gender minority rank; var exper salary; run; %mend corr;
C. Polychoric Correlation: Between categorical variable and categorical variable.
%macro corr (in, year); ods output measures=plcorr_&in._&year. (where=(statistic="Polychoric Correlation")); Title "Check Polychoric Correlation - &in. group"; proc freq data= &in._&year.; tables gender*rank minority*rank / plcorr; run; %mend corr;
D. Partial Correlation: Pearson correlation between variables while controlling other variables. Following example checks the correlation between salary and gender, controlling for rank and experience.
%macro partial (in, year); Title "Check Partial Correlation for basesal and gender - &in. group"; proc corr data=&in._&year. plots=scatter(alpha=.20 .30); var salary gender ; /* treat gender as continuous */ partial rank exper; run; %mend partial;
A. Scenario
The data set contains personal response on attribute 1 to attribute 4. The response can be either ‘Y’ or ‘N’. Some of the records are blank. The possible combinations for attribute 1 to 4 are 2x2x2x2, which is 16 combinations.
I would like to know how many people belongs any one of the 16 combination of the attributes. The distribution of people among the combination of attributes indicates the prominent attributes of the population (where the distribution is dense) and the outlier attributes (where the distribution is sparse).
B. Code
data combination; format attr1 $1. attr2 $1. attr3 $1. attr4 $1.; *Important to add format statement. The variables need to be exactly the same format as the data table that you want to run summary statistics on; do attr1= 'Y','N'; do attr2 = 'Y','N'; do attr3 = 'Y','N'; do attr4 = 'Y','N'; output; end; end; end; end; run;
proc tabulate data=data out = sum missing classdata = combination; *classdata option use the combination table created in the last step; class attr1 attr2 attr3 attr4; var count; table attr1*attr2*attr3*attr4, count*(sum=""); run;
C. Output
D. Notes
I have done a post of meta-analysis using the Proc Freq to produce cross tabulation of 2 by 2 table, the odds ratio, and the relative risk (column 1, column 2). In this post, I will show how the stats for odds ratio and relative risks are calculated using Excel.
A. SAS output
B. Excel
C. Interpretation
Drug: peole who feel better/people who did not improve = 58/30 = 1.93333
Placebo: people wo feel better/people who did not improve = 24/3 = 8
Odds ratio: of 0.241667 means patients who take the drug are 0.24 times likely to improve.
The probability of the improvement with the drug is 0.74 time the probability of the improvement with the placebo.
The probability of the no improvement in the symptoms with the drug is 3.7 time the probability of no improvement with the placebo.
A. Reference
B. Meta-Analysis
A meta-analysis is a statistical analysis that combines the results of multiple scientific studies. Meta-analysis can be performed when there are multiple scientific studies addressing the same question, with each individual study reporting measurements that are expected to have some degree of error. The aim then is to use approaches from statistics to derive a pooled estimate closest to the unknown common truth based on how this error is perceived.
Wikipedia
C. Problem with simply lumping the data from different studies together
D. SAS Solution (follow Hamer and Simpson’s paper, but corrected the output from the paper)
data chm; input study $ response $ trt $ cellfreq @@; datalines; study1 B P 24 study1 N P 3 study1 B D 58 study1 N D 30 study2 B P 16 study2 N P 57 study2 B D 2 study2 N D 10 ; run;
proc freq data=chm; tables study*trt*response /cmh; weight cellfreq; run;
E. SAS Output
F. Notes
G. Interpretation
* I will show the odds ratio and relative risk calculation in Excel in another post.