SAS Data Input: Creating Observations from Multiple Records - Prof. James Davenport, Study notes of Statistics

How to create multiple observations from the same record using sas, including examples of single and multiple input statements, line pointer controls, and variables list input. It also covers reading data from external files and accessing permanent sas data sets.

Typology: Study notes

Pre 2010

Uploaded on 02/12/2009

koofers-user-n8a
koofers-user-n8a 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
***Creating multiple observations from the same record***
Use the double trailing @@ -- this is another of the pointer
controls
@@ not only prevents a new record from being read into the
buffer when a new INPUT statement is encountered, but it also
prevents the record from being released when the program loops
back to the top of the DATA STEP -- Carefully read section
2.13 in your textbook.
Let’s look at some examples involving the census data of the 50
states and the falls data.
(See Program SAS_Lec04_input_01.sas)
(See Program SAS_Lec04_input_02.sas)
**Reading multiple records to create a single observation**
Suppose the data is recorded as follows:
1023 David Shaw
red
189 195
1049 Amelia Serrano
yellow
145 124
1
pf3
pf4
pf5

Partial preview of the text

Download SAS Data Input: Creating Observations from Multiple Records - Prof. James Davenport and more Study notes Statistics in PDF only on Docsity!

*****Creating multiple observations from the same record***** Use the double trailing @@ -- this is another of the pointer controls @@ not only prevents a new record from being read into the buffer when a new INPUT statement is encountered, but it also prevents the record from being released when the program loops back to the top of the DATA STEP -- Carefully read section 2.13 in your textbook. Let’s look at some examples involving the census data of the 50 states and the falls data. (See Program SAS_Lec04_input_01.sas) (See Program SAS_Lec04_input_02.sas) ****Reading multiple records to create a single observation**** Suppose the data is recorded as follows: 1023 David Shaw red 189 195 1049 Amelia Serrano yellow 145 124

There are four ways to read this data;

  1. single input statement
  2. multiple input statements
  3. using the “ / “ line pointer control
  4. using the “ #n “ line pointer control
  5. input idno 1-4 name $ 16-23 team $ strtwght endwght;
  6. a. input idno 1-4 name $ 6-23; input team $ 1-6; input strtwght 1-3 endwght 5-7; b. input idno 1-4; (this reads only idno & the input ; weights) input strtwght 1-3 endwght 5-7;
  7. " / " forces a new record to be read into the input buffer and the pointer to return to column 1 input idno 1-4 / / strtwght 1-3 endwght 5-7; (this does the same thing as 2b above) (See Program SAS_Lec04_input_03a.sas) (See Program SAS_Lec04_input_03b.sas) (See Program SAS_Lec04_input_03c.sas)

Reading Data from External Files This requires the use of another SAS “holy” word, namely INFILE The following statement must be placed in the “Data Step”, before the “INPUT” statement. infile 'E:\My Current Work Files\stat321-my data files\census.dat'; (See Program SAS_Lec04_census_data1.sas) Re: the census data examples. Creating Permanent SAS Data Sets for Future Use This again, introduces a new SAS “holy” word, namely LIBNAME. This statement must be place outside the “Data Step”; it is usually best to place it early in the program, up front near the “OPTIONS” statement. Libname jim "E:\My Current Work Files\stat321-mysdl"; Note, that the use of the library reference name “jim”. This is used in SAS’s two level naming system. This level, i.e. the first level has meaning only in the current program. (See Program SAS_Lec04_census_data2.sas) (See Program SAS_Lec04_census_data3.sas) Call attention the log file in the examples.

Accessing Permanent SAS Data Sets You must first specify the location and library reference name in the LIBNAME statement. Then within the Data Step, use the set statement: Data newone; Set librefname.datasetname; Proc contents; (See Program SAS_Lec04_census_data4.sas) Note: to bring into our work area an existing SAS data set, we use the “Set” statement within the Data Step. How do we know what’s in a permanent SAS data set? For that, we will need a procedure called “Proc Contents”.