This page is maintained by Jim Box

Frequently Asked SAS questions:

Submit A Question (Goes to everyone in STA 242)


Contents:

  1. Creating a SAS Dataset
  2. Converting a file to a SAS Dataset
  3. Sample form a Normal Distribution
  4. Add a variable to a Dataset
  5. Printing Graphics
  6. Highlighting points that aren't together

Creating a SAS Dataset from scratch

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

Sampling from a Normal Distribution

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.


Add a Variable to a Dataset

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


Printing Graphics

There are three main steps in printing SAS graphs:
  1. Telling SAS what to do with the file,
  2. Printing from the graphics window to a UNIX file
  3. 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.


Highlighting Points

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