/*
-----------------------------------------------------------------
File: ~carey/p5741dir/heights.save.sas
How to save raw data as a permanent SAS dataset
-----------------------------------------------------------------
*/
LIBNAME gregsets
'~carey/p5741dir/datasets';
/* In order to save a SAS data
set, SAS must know which directory
to save the data in. The LIBNAME statement gives a "nickname" of
no
longer than 8 characters to a directory. This LIBNAME statement
assigns the nickname gregsets to the directory
~carey/p5741dir/datasets */
DATA gregsets.heights;
/* To save a dataset as a
permanent dataset give it a two level
name in the DATA statement. The first level of the name is the
SAS
nickname for the directory (so SAS knowns where to physically
write
the dataset) and the seceond level is the name of the data set.
Hence,
this DATA statement will create a SAS data set called heights and
write it to the directory ~carey/p5741dir/datasets. After these
statements are executed, a unix file named heights.ssd01 will
appear in that directory. The "ssd" suffix signifies a SAS
dataset
and the "01" gives the type of computer (in this case, a Sun).
*/
/* Then just give the rest of the
statements for a creating a
SAS data set: */
INFILE
'~carey/p5741dir/datasets/heights.dat';
INPUT sex $ height @@;
IF sex='f' THEN csex=-1; ELSE csex=1;
heightin=height/2.54;
LABEL
height='Height (cm)'
csex='Sex contrast code'
heightin='Height (in)';
RUN;
/*
-----------------------------------------------------------------
File: ~carey/p5741dir/heights.save.sas
How to access a permanent SAS dataset
-----------------------------------------------------------------
*/
LIBNAME gregsets
'~carey/p5741dir/datasets';
/* Once again, use libname to
give a "nickname" to the directory
where the SAS dataset(s) is(are). Then, whenever you want to
access the dataset, always use the two level name convention of:
nickname.dataset_name. The following code gives some examples.
*/
DATA temp;
SET gregsets.heights;
/* Create a new dataset called
temp from the permanent data set
heights located on ~carey/p5741dir/datasets. */
PROC SORT data=gregsets.heights; BY
sex;
/* Sort the permanent dataset by the variable sex. */
PROC UNIVARIATE plot
data=gregsets.heights;
VAR height heightin;
/* Get univariate statistics on variables height and heightin
located in the permanent dataset heights */