FORS8000
Week 3: SAS data file
structure and working with data
SAS
Command
English Translation
data dog;
create datafile named
dog put in work library
set favorite.pets;
using datafile named pets
located in
favorite library
data
food.steak;
create datafile named
steak put in
food library
set meat;
using datafile named meat
located in work library
data
student.grades;
create datafile named
grades put in
student library
set tough.luck;
using datafile named luck
located in library
tough
Some Important Symbols
Comments are ignored in SAS and are useful for writing reminders.
Two types of SAS comments:
The asterisk (*)
followed by the message and ended with a semicolon (;)
* everything in here is ignored;
******** everything in here is ignored;
The forward slash and asterisk
(/*) followed by the message and ended with an asterisk and forward slash
(*/).
/* everything in here is ignored*/
/******** everything in here is ignored*/
Some important mathematical operators
Operation
SAS code
add X and
Y
X + Y
subtract
Y from
X
X - Y
multiply X and
Y
X * Y
divide X by
Y
X/Y
square
X
X ** 2
raise
X to the Y power X
** Y
take the natural
log of X log(X)
raise X to the e
exp(X)
(also called the
exponent)
Example: create datafile bass using datafile fish (both are located in the work library) and calculate relative weight (RW) of fish by dividing weight (WT) by total length (TL).
data bass;
set fish;
RW = WT/TL;
run;
REMEMBER: DON'T FORGET THE SEMICOLON (;) AT THE END OF EACH STATEMENT AND "RUN" AT THE END OF EACH PROGRAM