Excel and SAS
Excel and SAS
Excel and SAS
The following window should open. Select the type of file and the version you wish to import—
the default is MS Excel version 97 or 2000.
Then click next. The next window you will see asks you to locate the file you wish to import:
Browse to locate the file you wish to import and then click on options. This will enable you to
select the worksheet in Excel where the data is located.
Select the worksheet desired. (Note: By default, SAS assumes that the variable names are stored
in the first row of the Excel Worksheet. If that is not the case, remove the check mark next to
“Column names in first row.”) Then click OK. Then click next.
In the next screen you will type in the name that you want SAS to use to identify the dataset you
are importing (I called it sprinkler) and select the library you want SAS to store it in (the default
library is Work).
Then click finish or next. If you click finish, the new dataset will be stored in the Work library
and you can start working with it; but if you terminate SAS, the dataset will be deleted. If you
click next, on the following window, you have the option of telling SAS to create a program
with the statements that allow you import the file just by running the program. This is advisable
to do. For simplicity, call this program import.sas and store it in the desktop:
Click finish and then go to the desktop and open the file SAS created:
The first line tells SAS to create a SAS dataset in the library Work. The second line tells SAS
where the original data (it’s an Excel spreadsheet) is located on the computer. The third line tells
SAS the type of DBMS (database management system) used. In this case it was an Excel 2000
spreadsheet. The fourth line tells SAS the worksheet inside the Excel spreadsheet where the data
is located. The fifth line tells SAS to get the names from the first row in the Excel spreadsheet.
The last line tells SAS to run the above program.
When you hit the run button, SAS will import the data desired. You can use this file to program
more commands in SAS or you can copy the above code to the SAS file you are working with.
Important: As mentioned above, SAS clears the work library every time SAS is terminated.
Any datasets stored in this library will be lost and to restore then, you will either need to import
or create them again by running a program or using the menus. To bypass this, you could create
a permanent library in SAS. There are a few details concerning this but the code to do it is
libname rita "c:"; This code tells SAS that I will use my c: drive as a library, which I want
to call rita. SAS does not clear libraries created by you when it terminates.
The next time you need to import an Excel spreadsheet, you can either write the code and modify
it to fit the options of the new file, or you can import the data by using the menus in SAS.
When you run a regression, you can create datasets containing output information such as
parameter estimates, variance-covariance matrix, etc. You have to explicitly tell SAS to create
the output dataset and what you want to put in it. This is very convenient as these data can be
used as input for SAS or can even be exported into Excel.
Assume you want to create a dataset with the parameter estimates, which you later want to read
into Excel. The first step is to tell SAS to create the output dataset, after running the regression.
Note that the output statement has a different syntax according to the procedure you use. Check
SAS help for the correct syntax for the procedure you are using.
2. Proc NLMIXED
In NLMIXED you need to use the ODS (output delivery system) statement. The option to
request the parameter estimates is parameterestimates
proc nlmixed maxit=5000 tech=nrridg;
PARMS A=1 b=2 c=3 s2e=4;
Ytemp=A*(1-exp(b*X1))*(1-exp(c*X2))+err;
MODEL Y~normal(Ytemp,s2e);
RANDOM err~normal(0,s2e) subject=X3;
ods output ParameterEstimates=estimates;
run; quit;
Now that you have the parameter estimates in a SAS dataset in the Work library, you can export
this dataset into Excel if you wish to.
You can do this using the drop down menus as follows. First select the File menu and then
Export Data.
A window will open where you select the data you wish to export. You must choose the library
where the data is and then specify the name of the data. In our case, we select library Work and
dataset (member) estimates:
Then you must choose the format for exporting the data. In our case Excel 2000.
Then click next. At this point you must tell SAS where to store the Excel file and what to call it.
I will call it SASestimates.xls and for simplicity I am going to store it in the Desktop. Then click
next or finish. It is advisable to go to the next window instead of finishing.
In the next window, SAS will give you the option of creating a SAS file with the code for what
you just did. For simplicity, call the file export.sas and store it in the desktop. Always create a
new file when saving procedures created by SAS. If you save it as a file you already have, SAS
will overwrite the previous file.
Click finish. Go the desktop and make sure the Excel file exists.
The next time you need to export a file you can either modify this code or use the drop down
menus.
Good luck.