/*Importing direct data to SAS */ data direct; input age weight gender $; cards; 21 134 F 16 142 M 33 167 M ; run; /*Storing permanent data on SAS*/ libname test 'c:\' ; data test.direct; input age weight gender $; cards; 21 134 F 33 167 M 45 157 M ; run; libname test 'c:\'; proc print data=test.direct; run; /*Importing external data to SAS */ data scores; infile 'c:\scores.txt'; input height weight gender name $ score; run; data scores2; infile 'c:\scores2.txt'; input height 1-3 weight 4-6 gender 7 name $ 8-14 score 15-16; run; /*Exporting & importing MS Excel data*/ /*Exporting data to Excel data*/ proc export data=scores outfile="c:\scores.xls" dbms=excel2000 replace; *dbms stands for database management system; sheet="scores"; run; /*Importing data from Excel data*/ proc import out=impscores datafile="c:\scores.xls" dbms=excel2000 replace; sheet="scores"; getnames=yes; *getting the name of the variables names from external data; mixed=yes; run; /*To put observations in more than one line*/ data linecontrol; input #1 name $ height weight #2 country & $24. #3 score1 score2; cards; Ken 5.9 158 Great Britain 44 36 Pete 6.2 180 United States of America 32 29 ; run; /*To put several observations in one line*/ data oneline; input name $ score @@; cards; Joanne 23 John 34 Jimmy 45 Katrina 0 Chris 20 ; run; /*Transforming data and creating new variables*/ data trans; set scores; lnheight=log(height); logheight=log10(height); index=height/weight; run; /*Data Modification*/ data modify; set trans; if weight > 160 then delete; run; *'Set' command allows reusing created SAS data; /*To see the data in the output window*/ proc print data=scores; run; /*To see the contents of SAS data*/ proc contents data=scores; run; /*Sorting data*/ proc sort data=scores out=name; by name; *Sorts the data by name in alphabetical orders; run; proc sort data=scores out=height; by height; *Sorts the data by height in ascending orders; run; proc sort data=scores out=height2; by descending height; *Sorts the data by height in decending orders; run; /*To see basic simple statistics of data*/ proc means data=scores; run; *This provides the number of obvs, mean, std, min, and max of all numeric variables; /*Frequency procedure */ proc freq data=scores; run; *shows one-way frequencies; proc freq data=scores; tables gender*weight; run; *creates cross-tabulation table; /*Regression procedure*/ proc reg data=scores; model height=weight /dw alpha=0.01 clb; plot height*weight /conf pred cframe=ligr; run; /*Plotting data*/ proc gplot data=scores; plot height*weight; *height=vertical axis, weight=horizontal axis; run; /*Using advanced options*/ proc gplot data=scores; plot height*weight /skipmiss haxis=120 to 200 by 10 hminor=1 vaxis=5.0 to 7.0 by 1.0 vminor=1 regeqn cframe=gold; *Options for the plot statement; title font=arial c=blue box=3 bcolor=yellow 'Study of Height vs Weight'; *Putting the title for your graph; symbol i=rcclm95 value=dot height=1 cv=green ci=blue co=red width=2; *Setting the colors and size for the plot symbol and lines. i= can be also expressed as interpol=; run;