Paul D. Mcdonald, Spikeware, Inc., Schaumburg, Il: Paper 222-25
Paul D. Mcdonald, Spikeware, Inc., Schaumburg, Il: Paper 222-25
Paul D. Mcdonald, Spikeware, Inc., Schaumburg, Il: Paper 222-25
Paper 222-25
Web: http://www.SPIKEware.com/
ABSTRACT
This paper and its accompanying poster is prepared for SAS Users Table: Variations on normal application of “If _n_=1 then SET”
and SAS Programmers of any experience level. They review basic <value> Nobs1 = 1 1 < NOBS1 < NOBS1 >=
applications of the “IF _N_=1 THEN SET dsname” feature of the NOBS2 NOBS2
SAS Data Step. It allows merging one record-datasets to multiple- 1 Normal Uses first Use first
record datasets Operation record of record of
DATA1 only DATA1 only
INTRODUCTION Greater than Skips the first Skips the first Initializes all
1 and less _n_ _n_ variabels in
Ever have a one-record SAS dataset and you want that one record than nobs2 observations observations DATA1 for
attached to every record of another dataset? This idea is for you! and uses the final dataset
first record of and records
HOW IT WORKS DATA1 only them as
missing
THE CODE (EXAMPLE) Greater than Initializes all Initializes all Initializes all
Simply put, you have two “set” statements. The first one is nobs2 variables in variables in variables in
encountered only on the first record (if _n_=1) and is for the data set DATA1 for DATA1 for DATA1 for
of one record—in the example, AVGSALES. The second is the final dataset final dataset final dataset
main dataset that you want to add the one observation of the first on and records and records and records
to every observation—in the example, TOTSALES. them as them as them as
missing missing missing
data national;
if _n_=1 then set avgsales;
set totsales;
run;
CONCLUSION
The conclusion summarizes your paper and ties together any loose
ends. You can use the conclusion to make any final points such as
recommendations predictions, or judgments.
REFERENCES
SAS Language Guide (Reference) Version 6 First Edition, page 487.
CONTACT INFORMATION