Multiple DATA Steps
This program includes
multiple DATA steps and subsequently reads data five times from the
same Retail.Customer data set. Individual subsetting IF statements
appear in five separate DATA steps.
data retail.UnitedStates; set retail.customer; if country='US'; run; data retail.France; set retail.customer; if country='FR'; run; data retail.Italy; set retail.customer; if country='IT'; run; data retail.Germany; set retail.customer; if country='DE'; run; data retail.Spain; set retail.customer; if country='ES'; run; |
A Single DATA Step
This program uses only
one DATA step to create five output data sets. The data set Retail.Customer
is read only once. Also, IF-THEN/ELSE statements are used to conditionally
output data to specific data sets.
data retail.UnitedStates retail.France retail.Italy retail.Germany retail.Spain; set retail.customer; if country='US' then output retail.UnitedStates; else if country='FR' then output retail.France; else if country='IT' then output retail.Italy; else if country='DE' then output retail.Germany; else if country='ES' then output retail.Spain; run; |
A DATA Step and PROC SORT
This program has two
steps. The first step creates a SAS data set by subsetting observations
based on the value of the variable Country. The second step sorts
the data according to the values for each country. Passing through
all the data once and the subset again increases I/O and CPU operations.
data retail.CountrySubset; set retail.customer; where country in('US','FR','IT','DE','ES'), run; proc sort data=retail.CountrySubset; by country; run; |
PROC SORT with a WHERE Statement
In one step, this program
sorts data and selects only those observations that meet the conditions
of the WHERE statement. Processing only one data set once saves CPU
and I/O resources.
Note that if this program
did not create a second data set named Retail.CountrySubset, it would
write over the data set named Retail.Customer with only part of the
data.
proc sort data=retail.customer out=retail.CountrySubset; by country; where country in('US','FR','IT','DE','ES'), run; |
SAS Data Set
|
Variable Name
|
Variable Format
|
---|---|---|
Retail.Customer
|
Country
|
$COUNTRY.
|
Retail.Customer
|
Birth_Date
|
DATE9.
|
Retail.NewCustomer
|
Country_ID
|
$COUNTRY.
|
Retail.NewCustomer
|
Birth_Date
|
MMDDYYP10
|
A DATA Step
This program uses a
DATA step with a RENAME statement and a FORMAT statement to modify
attributes for the variables Country_ID and Birth_Date.
data retail.newcustomer; set retail.newcustomer; rename Country_ID=country; format birth_date date9.; run; |
PROC DATASETS
This program uses PROC
DATASETS to modify the names and formats of the variables Country_ID
and Birth_Date.
proc datasets lib=retail nolist; modify newcustomer; rename Country_ID=country; format birth_date date9.; quit; |