230 likes | 361 Views
Module I: Elementary Data Step Techniques. Madan Gopal Kundu. SAS Resources. SAS Procedures guide: http://www.caspur.it/risorse/softappl/doc/sas_docs/proc/index.htm The Little SAS Book by Lora D Delwiche and Susan J Slaughter http://www.ats.ucla.edu/stat/sas/notes2/.
E N D
Module I: Elementary Data Step Techniques Madan Gopal Kundu
SAS Resources • SAS Procedures guide: http://www.caspur.it/risorse/softappl/doc/sas_docs/proc/index.htm • The Little SAS Book by Lora D Delwiche and Susan J Slaughter • http://www.ats.ucla.edu/stat/sas/notes2/
Introduction • Statistical Analysis System • Developed by Jim Goodnight in1970 at N.C. University for Agricultural Research • SAS Institute founded in 1976 • 98 of world’s top 100 company in Fortune 500 use SAS • SAS Macro facility
SAS Windows To write/ modify SAS program code • Editor • Log • Output • Result • Explorer • Graph • To check execution of the program. • Helps in identify the error in SAS code • Tells about details such as amount of time it taken to execute the code It displays the output generated upon execution of SAS code It displays index of the output It displays the list of libraries (containing SAS dataset), formats, compiled macros and graphs It displays graph
EXPLORER OUTPUT RESULT LOG EDITOR
Layout of SAS Programs • SAS statement can be in upper- or lower case • All statements end with semicolon (;) • Statement can continue on the next line • Statements can be on the same line as other statements • Statements can start on any column
Statement to generate library Name of the library Path of the library Crating SAS Library • Programmatically – Using LIBNAME statement • LIBNAME newlib ‘C:\’; • Non-programmatically
Variable name • Maximum 32 characters • Must start with a letter or an underscore • Contain only letters, numerals or underscores • Can contain upper- and lower case letters • Character variables always followed by $
Creating Datasets in SAS • Using Data step DATA newlib.one; INPUT name $ roll score; CARDS; Ramen 122 95 Chris 123 84 Neha 124 90 Abdul 125 91 ; RUN; ?? newlib.one : The dataset ONE is in the library NEWLIB
Importing Data in SAS • Import Wizard • Proc import • Data step
Existing dataset Create SAS Dataset from already existing SAS dataset… DATA two; SET one; RUN; New dataset
Managing SAS dataset • SET statement • KEEP statement • DROP statement • RENAME statement • WHERE statement • DELETE statement • LABEL statement
KEEP statement DATA new; SET sashelp.class; KEEP name sex age; RUN; It will keep only the selected variables. Remaining variables will be dropped.
DROP statement DATA new; SET sashelp.class; DROP name sex age; RUN; It will drop all the selected variables. Remaining variables will be as such.
RENMAE statement DATA new; SET sashelp.class; RENAME Sex=Gender; RUN; Used to change the variable name.
LABEL statement DATA new; SET sashelp.class; LABEL Age=‘Age (Yrs)’ Weight=‘Weight (Kg)’; RUN; Used to label the variable names.
WHERE statement DATA new; SET sashelp.class; WHERE sex=‘F’; RUN; Used to add some condition to the dataset.
WHERE statement DATA new; SET sashelp.class; WHERE Age>13; RUN; Used to add some condition to the dataset.
Merging datasets • Sort the dataset using PROC SORT • Merge the datasets in datastep
Merging datasets ONE TWO + FINAL
SAS System options • CENTER| NOCENTER • DATE|NODATE • LINESIZE=n (64-256) • PAGESIZE=n (15-32767) • PAGENO=n • RIGHTMARGIN=n • LEFTMARGIN=n • TOPMARGIN=n • BOTTOMMARGIN=n
Task… • Create a library in SAS • Create the following SAS dataset • Get a copy of that dataset using SET statement • Label the variable WT as ‘Weight (kg)’