APPENDIX D
QUICK REFERENCE
This appendix provides a series of brief descriptions of basic SAS® tasks. Most of the tasks are listed here without explanation, except for a reference to a chapter.
Ways to name a data set – can be used whenever a dataset is named:
DATA SOMEDATA; * create working/temporary data set;
DATA “C:\SASDATA\SOMEDATA”; *create permanent data set
in specified location;
LIBNAME MYSASLIB “C:\SASDATA”; * create a temporary SAS library;
DATA MYSASLIB.SOMEDATA; * create permanent data set in MYSASLIB
library;
Versions of the INPUT statement:
* freeform input;
INPUT ID $ GENDER $ SBP DBP WEIGHT;
* column numbers specify location of data;
INPUT ID 1-4 SEX $ 5-5 AGE 6-9;
* specify beginning column, name, informat.
INPUT @1 ID 4. @5 SEX $1. @10 BDATE DATE9.;
Read date using format specification (see format table, Appendix A):
DATA MYDATA;
INPUT @1 FNAME $11. @12 LNAME $12. @24 BDATE DATE9.;
DATALINES;
Bill Smith 08JAN1952
;
RUN;
Ways to specify source of data or enter data set:
DATALINES; * data are listed in the code following
this statement;
INFILE filename; * data are in an ASCII file on disk;
SET dataset; * data are in a SAS data file;
PROC IMPORT; * imports data from a non-SAS filetype;
Common ways to manipulate data within the DATA step (Chapters 4–7):
* Conditionally specify missing value; IF AGE LE 0 then AGE = .; IF SBP GE 140 THEN HIGHBP=1; ELSE HIGHBP=0; * If-Then-Else; IF GENDER="MALE"; * Subsetting if statement; * Define label for a variable name; LABEL ...
Get SAS Essentials: Mastering SAS for Data Analytics, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.