Frequently Asked Questions (FAQs)
How can I input data in SAS?
Directly entering data in SAS
Data can be directly typed in a SAS data step. For example, if you want to create a SAS dataset 'healthy' with four variables var1, var2, var3, var4, just input the following information and run the code.
INPUT var1 var2 var3 var4;
0 1 1 82
0 1 1 72
1 1 2 10
1 2 2 12
Please note that four columns of data lines correspond to four variables (in the given order).
Reading raw data
Raw data can be read in SAS using an INFILE statement. For example, if the raw data with four variables var1, var2, var3, var4 is in the file 'health.dat' in the directory 'C:\myfolder', the following code will create a SAS dataset 'healthy':
INPUT var1 var2 var3 var4;
Reading SAS data
A SAS dataset can also be read similar to raw data but by using SET instead of INFILE statement (and you do not need to input variable names). For example, if we have a SAS dataset 'health' saved in the directory 'C:\myfolder' the following code will create a new dataset 'healthy'.
Reading SAS data with a LIBNAME statement
A SAS library can be created by LIBNAME statement. All the datasets in that library can then be referred by library reference (LIBREF). For example, the following code will assign LIBREF 'xyz' to a directory 'C:\myfolder';
LIBNAME xyz 'C:\myfolder'; /* xyz is SAS LIBREF */
Once LIBREF is assigned, any SAS dataset in that library can be loaded by just prefixing LIBREF with the dataset name. This is the best way of inputting data. For example, a SAS dataset 'health' located in the directory 'C:\myfolder', can be called simply by prefixing LIBREF to the dataset name:
% unilogistic (
dsn = xyz.health,
Importing data from an Excel file
Suppose an Excel dataset is saved in 'sheet 1' of file 'health.xls' in the directory 'C:\myfolder'. The following code will import Excel data and create a SAS data set 'healthy':
PROC IMPORT]] OUT= healthy /*SAS file name */
DATAFILE= "C:\myfolder\health.xls" /* Excel file name */
DBMS=EXCEL REPLACE; /* Replace if exists */
SHEET="sheet 1"; /* Name of the excel sheet */
[[b|| GETNAMES=YES; /* Get Heading names? */
Note: Data can also be imported by clicking FILE menu and then IMPORT DATA...
Importing data from an Access database
Importing data from a Microsoft Access database is similar to that from an Excel file. For example, the following code will import a table 'MyTable' in the database 'health.mdb' saved in the directory 'C:\myfolder' and create a SAS data set named 'healthy':
PROC IMPORT OUT= healthy /*SAS file name */
DATATABLE= "MyTable" /* Access table name */
DBMS=ACCESS2000 REPLACE; /* Replace if exists */
DATABASE= "C:\myfolder\health.mdb"; /* Access database name */
Note: Access data can also be imported by clicking FILE menu and then IMPORT DATA...
How do I load a macro?
Directly from the Macro file
Macros can be called simply by running the code just like any other SAS program.
Open the file with the macro code.
Select the code and click RUN.
Without opening the macro file
If macros are saved in a directory, they can be conveniently called whenever required, without opening the file. Suppose the macro UniLogistic is saved in the directory 'C:\myfolder', it can be loaded using INCLUDE statement:
% include 'C:\myfolder\unilogistic.sas'
Creating SAS auto call libraries
If you use SAS macros quite often, you can set up an autocall macro library where all macros can be saved. SAS will automatically search for that directory when you invoke a macro. Click here to go to SAS document to learn more about auto-call libraries.
What programmes do I need to implement these macros?
You need SAS (BASE SAS and SAS/STAT) and MS Excel to implement these macros. In addition, you require Adobe Acrobat Reader to view the graphs produced by the macros.
Which version of SAS do I need?
These macros require SAS version 9 and above. They have not been tested on previous versions.
What SAS procedures are used by the macros?
Macros for logistic regression use PROC LOGISTIC while that for linear regression use PROC GLM, hence their names.
The macros run these procedures iteratively to conduct analyses and then export required results to Excel. In addition to these core procedures, the macros use a host of other SAS procedures and commands to bring you the required results according to your options.