0% found this document useful (0 votes)
1K views3 pages

Sas Cheat Sheet

1. This document provides a cheat sheet for common SAS procedures and tasks for working with data, including reading in data, modifying datasets, merging datasets, graphical procedures, reporting procedures, and various analysis procedures like FREQ, GENMOD, GLM, MEANS, MIXED, REG, SURVEYSELECT, and TTEST. 2. Key tasks covered include importing data from databases, subsetting and stacking datasets, deriving new variables using functions, producing graphical and tabular output, and exploring relationships between variables through various statistical modeling and analysis procedures. 3. Useful formatting options, informats, functions, and procedures are highlighted to help with common data management and analysis tasks in SAS.

Uploaded by

prash.raju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views3 pages

Sas Cheat Sheet

1. This document provides a cheat sheet for common SAS procedures and tasks for working with data, including reading in data, modifying datasets, merging datasets, graphical procedures, reporting procedures, and various analysis procedures like FREQ, GENMOD, GLM, MEANS, MIXED, REG, SURVEYSELECT, and TTEST. 2. Key tasks covered include importing data from databases, subsetting and stacking datasets, deriving new variables using functions, producing graphical and tabular output, and exploring relationships between variables through various statistical modeling and analysis procedures. 3. Useful formatting options, informats, functions, and procedures are highlighted to help with common data management and analysis tasks in SAS.

Uploaded by

prash.raju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.3 Common out FORMATS 3.

2 Selecting vriables
• w.d standard numeric DATA dsname;
• $n character SET dsname;
SAS Cheat Sheet for Stat-342 • COMMAw.d numeric values with commas ...
• DATEw.d,YYMMDDw. - use the ISO standard with 4 digit KEEP var1 var2 ...;
Carl James Schwarz years! DROP var1 var2 ....;
run;
April 9, 2016 1.4 Format modifiers
3.3 Merging datasets
Used typically with list input to modify the format attached to a
variable. Proc SORT data=DS1; by bvar1 bvar2 ...; run;
1 Reading data files into SAS dataset • (colon) : typically used for numeric variables for Proc SORT data=DS2; by bvar1 bvar2 ...; run;
dates/times/commas etc. DATA both;
DATA dsname1(dsoptions) • (ampersand) & used for character values with embedded MERGE ds1 ds2 ....;
dsname2(dsoptions) ....; blanks BY bvar1 bvar2 ....;
INFILE filelocation infileoptions; run;
LENGTH cvar1 $length1 What happens if records are in one dataset but not the other?
cvar2 $length2 ....; 2 Importing data from database systems Refer to manuals for use of IN= variables to keep track of which
INPUT var1 cvar2 var3 cvar4 ....; dataset is active in the merge.
ATTRIB var1 LABEL= FORMAT= ; Proc IMPORT FILE=filename
... processing statements .... OUT=dsname DBMS=dbms REPLACE; 3.4 Stacking datasets
run; GUESSINGROWS=nnnn;
GETNAMES=yes; Proc SORT data=DS1; by bvar1 bvar2 ...; run;
run; Proc SORT data=DS2; by bvar1 bvar2 ...; run;
1.1 Important INFILE options Common dbms are csv. DATA both;
SET ds1 ds2 ....;
• MISSOVER BY bvar1 bvar2 ....;
• DLM= DSD
• FIRSTOBS=
3 Modifying existing SAS datasets run;

3.1 Subsetting observations 3.5 Derived variables and functions


1.2 Common INFORMATS
DATA dsname; SAS has an extensive list of function. See the help file for details.
Use the : format modifier with these formats. SET dsname; Useful functions are:
• COMMAw.d numeric values with commas IF condition ; • day(date), month(date), year(date), weekday(date), etc.
• $ character data, but don’t forget the LENGTH IF condition then DELETE; • index(text, string)
• ANYDATEw accommodates a variety of dates but look at .... statements .... • max(var1, var2, ....), min(), sum(), mean() etc.
documentation! run; • round(var)

1
• substr(test, begin, length) - differs from C 6 Analysis Procedures OUTPUT OUT=
• upcase(), lowcase() - change case of text statistic(var)=name ....;
• word(string, n) 6.1 FREQ run;

Proc Freq data= ; Popular statistics are n, mean, stddev, stderr, lclm, uclm. See
table v1 * v2 / chisq nocol nopercent; also SUMMARY.
4 Graphical Procedures run;

Proc SGPLOT data=dsnamel;


6.2 GENMOD 6.6 MIXED
SCATTER X= Y= / GROUP=;
HIGHLOW X= HIGH= LOW= ; Prog GENMOD data=...; 6.7 REG
XAXIS label= class group;
order= model y = group / dist=binomial Proc REG data=....l
offset=(left, right); link=logit type3; model y= x1 x2 x3 / clb;
Check manual for many other options. lsmeans group / cl diff run;
adjust=tukey ilink;
ods output lsmeans=.....;
6.8 SURVEYSELECT
5 Reporting Procedures See also LOGISTIC for logistic regression models;
Proc surveyselect data=population
5.1 PRINT 6.3 GLIMMIX out=sample
method=
Proc PRINT DATA=dsname(OBS=nnn) 6.4 GLM sampsize= samprate=
LABEL SPLIT NOOBS; seed=
VAR var1 var2 ...; Avoid using GLM for any linear mixed models. Use MIXED.
outhits
ATTRIB var1 LABEL= FORMAT= ; proc GLM data= ...;
reps=;
PAGEBY var; class ...
run;
run; model y = x;
Common methods are srs and urs. Specify the sampsize= or
lsmeans x / lines cl pdiff adjust=tukey;
samprate= but not both. Many other methods and ways to spec-
ods output lsmeans=....;
ify sampling (e.g. if clustering exists) can be specified. Many
5.2 TABULATE run;
other similar procedures for analysis of survey data.
Proc TABULATE DATA=dsname MISSING;
6.5 MEANS
CLASS pagevar1 rowvar2 rowvar3 colvar4 ...; 6.9 TTEST
VAR analvar ...; Proc SORT data=dsname;
TABLE pagevar1, BY bvar1 bvar2 ...; run; Proc TTEST data=....l
rowvar2*rowvar3, Proc MEANS DATA=dsname NOPRINT; class group;
colvar4*analvar*(N*F=w.d MEAN*F=w.d...);BY bvar1 bvar2 ...; var var1; /* independent sample */
run; VAR var1 var2 ...; run;

2
Always use the Welch version of the t-test. Paired statement set wide; 10 Generating random numbers
used for paired t-test or use Proc Univariate on difference. length test $10.;
grade = t1; test="Test1’; output; SAS has a complete set of function to generate pseudo-random
grade = t2; test="Test2’; output; numbers. Some examples are:
6.10 UNIVARIATE
.... • ranuni(seed);
p rand(’uniform’); a U[0,1] with E=.5 and
Proc UNIVARIATE data=.... cibasic robustscale;drop t1 t2 ....; SD= 1/12.
var var1 var2 ....; run; • rannor(seed); rand(”normal”); a N(0,1) with E=0, and
output out= statistic(variable)= ; SD=1; p
run; proc transpose data=long out=wide; • rand(”lognormal”) with E=e.5 , and SD= (e − 1)e.
Generate lots of output! Can also generate histograms etc, but I by studentnumber;
prefer SGplot. var grade;
id test; 11 Bootstrapping
run;
7 Split-Apply-Combine General procedures for CRD/SRS and statistics related to the
mean.
The BY statement can be used with any procedure along with
• Resample K times with replacement from the original
ODS tablename=dsname to send selected output to a SAS
dataset.
9 Sending SAS output to other destina- dataset using Proc SurveySelect and the method=urs,
sampfrac=1 , outhits and reps= options.
Proc SORT data=dsname; by ....; tions • Compute estimate for each bootstrap sample.
Proc BLAH data=dsname;
• Look at bootstrap sampling distribution to compute rele-
BY bvar1 bvar2; Refer to manual for extensive help on using ODS. Common us- vant quantities of interest.
... statements... age to create PDF or MSWord document.
ODS tablename=newds;
ODS PDF FILE=’filename.pdf’ style=.....;
run;
.... procedures that generate output ... 12 Macro Variables
ODS PDF CLOSE;
8 Wide-Long and Long-Wide ODS RTF FILE=’filename.rtf’ style=.....; %LET mvar= ...; /* sets the macro variable */
.... procedures that generate output ... Use &mvar where you want to replace the macro variable by the
data long; ODS RTF CLOSE; assigned text. Careful of quotes, i.e. “&mvar” vs ‘&mvar’.

You might also like