SAS for Programmers

Libraries and Data sets 

SAS stores data on the hard disk (HDD). The folders/directories that it saves the data are called libraries.  
  • WORK - Default temporary library. No need to define it. Always available.
  • User defined library - This needs to be defined using a libname staetment
    • libname <library-name> '<library-location-path>';
    • e.g. libname D 'D:\data';
SAS stores data in data sets. These are similar to database tables. Data sets need to be prefixed by the library name. e.g. D.states. However, temporary data sets (in the work library) do not need a prefix. e.g. states.

Loading Data into SAS

SAS is capable of importing data from various sources. proc import is the most straight forward way of importing data to SAS. 
  • CSV - 
proc import datafile="<filename>"
     out=<out_data_set>
     dbms=csv
     replace;
run;
  • Excel - 
proc import datafile="<filename>"
     out=<out_data_set>
     dbms=excel
     replace;
run;

Exporting Data

  • CSV - 
proc export data=<Data_set>
outfile='<filename>'
dbms=dlm;
delimiter='|';
run;
  • Excel - 
proc export 
  data=<Data_set>
  dbms=EXCEL2010 
  outfile="<filename>..xlsx" 
  replace;
run;

Processing Data

SAS is capable of running SQL queries on its data sets. This the most straight forward way of manipulating data. It also avoids the need to learn SAS data statements. 

proc sql;
  <any SQL statement>;

e.g. 
proc sql;
  create table results_table as 
    select *
    from D.table1 A inner join D.table2 B
        on A.code = B.code;







Comments