Creating Multiple Observations from a Single Record |
Lesson
Summary![]() ![]() |
This page contains |
I. Text Summary
To go to the page where a task, programming feature, or concept was presented, select a link. |
File Formats One raw data record can contain enough information to produce several observations. Data is stored in this manner to reduce the size of the entire file. The data can be organized into |
Reading Repeating Blocks of Data To create multiple observations from a record that contains repeating blocks of data, the DATA step needs to hold the current record until each block of data has been read and written to the data set as an observation. The DATA step should include statements that
|
Reading the Same Number of Repeating Fields To create multiple observations from a record that contains an ID field and the same number of repeating fields, you must execute the DATA step once for each record, repetitively reading and writing values in one iteration.The DATA step should include statements that
|
Reading a Varying Number of Repeating Fields
To create multiple observations from a record that contains an ID field and a varying number of repeating fields, you must execute the DATA step once for each record, repetitively reading and writing values in one iteration while the value of the repeating field exits.The DATA step should include statements that
|
II. Syntax
To go to the page where a statement or option was presented, select a link. |
Repeating Blocks of Data |
LIBNAME libref 'SAS-data-library'; |
FILENAME fileref 'filename'; |
DATA SAS-data-set; |
INFILE raw-data-file; |
INPUT variables @@; |
RUN; |
An ID Field Followed by the Same Number of Repeating Fields |
LIBNAME libref 'SAS-data-library'; |
FILENAME fileref 'filename'; |
DATA SAS-data-set; |
INFILE raw-data-file; |
INPUT id-variable @; |
DO index-variable specification; |
OUTPUT; |
END; |
RUN; |
An ID Field Followed by a Varying Number of Repeating Fields |
LIBNAME libref 'SAS-data-library'; |
FILENAME fileref 'filename'; |
DATA SAS-data-set; |
INFILE raw-data-file MISSOVER; |
accumulator-variable=0 |
DO WHILE (expression); |
accumulator-variable+1 |
OUTPUT; |
INPUT repeating-variable @; |
END; |
RUN; |
|
III. Sample Programs
Repeating Blocks of Data libname perm 'c:\records\weather'; filename tempdata 'c:\records\weather\tempdata'; data perm.april infile tempdata; input Date : date. HighTemp @@; format date date7.; run; |
An ID Field Followed by the Same Number of Repeating
Fields
libname perm 'c:\records\sales'; filename data89 'c:\records\sales\1989.dat'; data perm.sales89; infile data89; input ID $4. @; do Quarter=1 to 4; input Sales : comma. @; output; end; run; |
An ID Field Followed by a Varying Number of Repeating
Fields
libname perm 'c:\records\sales'; filename data89 'c:\records\sales\1989.dat'; data perm.sales89; infile data89 missover; input ID $4. Sales : comma. @; Quarter=0; do while (sales ne .); quarter+1; output; input sales : comma. @; end; run;
|
IV. Points to Remember
|
![]() |
![]() |
Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.