This page is maintained by Jim Box
Frequently Asked SAS questions:
Submit A Question (Goes to everyone in STA 242)
Contents:
- Creating a SAS Dataset
- Converting a file to a SAS Dataset
- Sample form a Normal Distribution
- Add a variable to a Dataset
- Printing Graphics
- Highlighting points that aren't together
-
-
If you want to enter a dataset from scratch, follow the steps in the following sample (don't forget the semi-colon!!!).You should type these statements in the PROGRAM EDITOR window. Italics indicate names specific to this dataset.
data sasuser.example;
input SAT GPA ;
datalines;
1270 3.65
1000 3.27
1550 3.95
800 2.65
920 3.05
700 2.17
; {NOTE: this semicolon tells SAS that this is the end of the data}
run;
Now, to get SAS to process this, go to the Locals pull-down menu and choose Submit. You should see "NOTE: 11 Lines submitted." You now have a SAS dataset to use.
Converting a file to a SAS Dataset
Suppose you have a dataset saved in a file and would like to convert it into a SAS dataset. The first thing to do is to save the data without any column headers. Now, type the following commands at the PROGRAM EDITOR window:
options linesize = 130; {Or larger, as the case may be}
data name;
infile '/lorax/local/www/htdocs/courses/sta242-S96/Data/filename';
input student $ 1-10 sat gpa;
run;
Then choose Submit form the Locals Menu
NOTES:
- You must use the entire path name. If you are uncertain, and you have the data in an emacs window, just save it, and emacs will tell you exactly the pathname
- The $ tells SAS that you just named a variable that is a character string instead of numeric. The default is eight characters - if you need more, tell SAS exactly what columns to use. Be careful - get the exact columns. I usually count them in the emacs window
- Variable names are limited to eight characters, and must start with a letter.
- SAS will save this to the WORK library. To save it into the permanaent library, call up the dataset in INSIGHT, choose File ... Save-> ... Data, and select the SASUSER Library
To generate samples from a normal distribution, put the following lines of code in the PROGRAM EDITOR window:
data dataset name ;
mu = whatever;
sigma = whatever;
N = whatever;
do i = 1 to N;
rn = rannor(0);
y = sigma*rn + mu ;
output;
end;
run;
Then Submit form the Local Menu.
This dataset will be saved in the WORK library, which is temporary. To save it into the permanent library, open the file from the work directory, and in the data window choose File ... Save-< ... Data and choose the SASUSER library.
If you know ahead of time that you want to make this a permanent dataset, replace the first command in the above program with data sasuser.dataname.
INSIGHT has several built in transformations, but if you need to add something to your dataset and cant use the transformation menu, submit the following commands at the PROGRAM EDITOR:
data sasuser.dataname;
set sasuser.dataname;
newvar = -1*(oldvar**-3);
run;
NOTE: ** means raise to an exponent in sasspeak
There are three main steps in printing SAS graphs:
- Telling SAS what to do with the file,
- Printing from the graphics window to a UNIX file
- Printing the UNIX file
1. Telling SAS what to do with the file:
Cut-and-paste the following commands into the Program Editor window: (do not forget the ;)
filename gsasfile 'boxplot';
goptions target=ps gaccess=gsasfile gsfmode=replace noprompt;
Then select Submit from the Locals menu.
2. Printing from the graphics window to a UNIX file:
In the graphics window, select File:Print That will save the file boxplot in your directory.
3. Printing the UNIX file:
Go over to the UNIX window and type
ls
That makes a list of the files in your directory. One of them should be boxplot. To send it to the printer, type
print boxplot
at the UNIX prompt.
The next time you want to print something in this session, just type:
filename gsasfile 'nameoffile';
in the Program Editor window, then repeat steps 2 and 3.
The next time you start a SAS session, you must repeat all three steps.
To highlight points or tables that are not next to each other, hold down the Ctrl button while pressing the mouse button.
SAS Institute Homepage