20 SQL in SAS: Setup
20.1 Read Data
In the following example, we are reading the tab-delimited data (
tblStudent.txt) on the SAS environment using thePROC IMPORTstatement and assign the table nametblStudent.You may have to check the delimiter option while calling
PROC IMPORTfor your data.The arguments
getnames=YESassign the variable names from the first row andguessingrows=MAXdetermines the length and data type of variables.You may read the
.CSVor.XLSXfiles using the appropriatePROC IMPORTcommands.You can also download the SAS binary data as a zipped file and use directly.
# Give your own path
libname SASData 'Path\To\Folder\data';
proc import datafile = 'Path\To\Folder\data\tblStudent.txt'
dbms=dlm REPLACE out=SASData.tblStudent;
delimiter='09'x;
getnames=YES;
guessingrows=MAX;
run;
20.2 Run SQL Query
You can run SQL query in SAS using
PROC SQL.Include the
quitstatement to terminate the SQL procedure.The macro variable
putis included to check the total number of records in the log window.
# Provide your own path
libname SASData 'Path\To\Folder\data';
proc sql;
SELECT *
FROM tblStudent
;
quit;
%put NUMBER_RECORDS = &sqlobs;
20.3 SAS Script

20.4 SAS Outputs
