Review of the data step and how it worksA simple exampleThe most important things about the data step you can learn from this example:
data alpha;
infile cards;
input a b c;
d = c - b;
cards;
1 5 10
0 8 7
1 4 6
;
run;
proc print data = alpha;
run;
The lines beginning with "data alpha;" and ending with the first "run;"
are a simple example of a SAS data step. This data step creates
a temporary SAS data set named "alpha" and it exists in the default WORK library.
Questions:1. What is meant by a "temporary SAS data set?" How many observations and how many variables are in the data set alpha? Answer.
/smith/project/data/part1.datAnswer.
input a b c;to read d = c - b;Answer.
Answers:2. Three rows (corresponding to the three observations) and four columns (corresponding to the four variables) showing the values of the variables on each observation. The OBS column gives observation number. OBS A B C D 3. The PDV is an area in memory where the SAS observation that will be output is formed. You can picture the PDV on the first iteration of the data step (first time through) like this. Before input a b c; is executed: A B C D After input a b c; is executed: A B C D After d = c - b; is executed: A B C D 4. After d = c - b; is executed. 5. The variables a b c d in the PDV are reset to SAS missing and the statement input a b c; is executed again if there is more data to read. 6. Default actions:
7. Nothing. 8. This program would do it: filename in '/smith/project/data/part1.dat'; 9. The value of D would be SAS missing on all observations. 10. You would add a libname statement and use a two-part name for the data set to be written. The libname statement will associate a name of your choice (a "library reference" or "libref" for short) with a name the operating system will recognize as a place to write the permanent SAS data set. That place, on a directory-based system, is simply a directory, and all the SAS files stored there constitute a "SAS data library." Here is how a libname statement could be used to create a permanent SAS data set alpha in the directory /smith/project/data_sas/. libname out '/smith/project/data_sas/'; Review again? Another topic? Questions or comments? If you are affiliated with the Carolina Population Center, send them to Phil Bardsley.
|

