Show Menu
Cheatography

SAS33344 Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Prelim­inaries

click here to download SAS University Edition*
*Free Software for Learning

Get your data into a DataFrame

Load a DataFrame from a CSV file

proc import datafi­le=­"­C:­\fil­e.c­sv"
out=ou­tdata
dbms=csv
replace;
getnam­es=yes;
run;
Note: often works. Refer to SAS docs for all arguments

From inline csv text to a DataFrame

data names;
infile datalines delimi­ter­=',';
input first $ last $;
datalines;
Ali,Ajouz
Karam,­Ghawi
;
Note: The DATALINES statement does not provide input options for reading data. However, you can access some options by using the DATALINES statement in conjun­ction with an INFILE statement.

Saving a DataFrame

 

Saving DataFrame to csv file

proc export data=s­ash­elp.HEART
outfil­e="/­fol­der­s/m­yfo­lde­rs/­fil­e.c­sv"
dbms=csv
replace;
run;
Note: often works. Refer to SAS docs for all arguments

Saving DataFrame to Excel Workbook

proc export data=s­ash­elp.class
outfil­e="/­fol­der­s/m­yfo­lde­rs/­fil­e.x­lsx­"
dbms=XLSX
replace;
run;
Note: often works. Refer to SAS docs for all arguments
 

Working with the whole DataFrame

 

Peek at the DataFrame contents

/* Data set attributes + columns list */
proc datasets ;
contents data=S­ASH­ELP.HEART order=­col­late;
quit;


/* Data Header (first 5 rows) */
proc print data=s­ash­elp.class (obs=5);
run;

/* Data Footer (last 5 rows) */
%let obswant=5;
data want;
set sashel­p.class nobs=o­bsc­ount;
if _n_ gt (obsco­unt­-&­obs­want.);
run;

proc print data=want;
run;