Directing data step output
LECTURE#8: Controlling DATA Step Processing
Setting Up for This Course
The complete SAS programming process includes accessing data, exploring and validating data, preparing data, analyzing and reporting on data, and exporting results. But it is likely that the majority of your time as a programmer is spent preparing data. For this reason, the rest of the course is focused on the SAS DATA step and various procedures that expand your skills and help make you more productive working with your data.
In “Creating Custom Formats,” you learn how to create and use custom formats to enhance how your data is displayed in a table or report.
In “Combining Tables,” you learn how to concatenate tables, merge tables, and identify matching and nonmatching rows.
The detailed international storm data can be found at https://www.ncdc.noaa.gov/ibtracs/index.php?name=wmo-data as part of the International Best Track Archive for Climate Stewardship (IBTrACS). The data has been summarized and cleansed to use in this course.
The US National Park data can be found at https://irma.nps.gov/Stats/Reports/National. The data has been summarized and cleansed to use in this course.
Understanding DATA Step Processing
Practice
Level 1
What will be assigned for the length of Size?
Run the program and examine the results.
At the end of the DATA step, write the contents of the PDV to the log.
Run the program and read the log to examine the messages written during execution.
Directing DATA Step Output
Controlling Row Output
Scenario
Files
p201d02.sas
storm_summary – a SAS table that has one row per storm for the 1980 through 2016 storm seasons
Notes
The OUTPUT statement followed by a table name writes the contents of the PDV to the specified table.
Demo
Open the p201d02.sas program in the demos folder and find the Demo section. Modify the DATA statement to create three tables named indian, atlantic, and pacific.
length Ocean $ 8;
Basin=upcase(Basin);
output indian;
end;
else do;
Ocean="Pacific";
drop MaxWindMPH;
Controlling
Column Output 
Scenario
Files
storm_summary – a SAS table that has one row per storm for the 1980 through 2016 storm seasons
Notes
DROP= or KEEP= data set options can be added on any table in the DATA statement.
Demo
Add a DROP= data set option in the SET statement to drop MinPressure. Start the debugger. Notice that MinPressure is not included in the PDV.
set pg2.storm_summary(drop=MinPressure);
Learn about the SELECT-WHEN-OTHERWISE statement in SAS Help.
Practice
If you restarted your SAS session, open and submit the libname.sas program in the course files.
Level 1
Submit the program and verify the output.
The notes in the SAS log indicate how many rows are in each table.
Level 2
Conditionally Creating Columns and Output Tables
The pg2.np_2017 table contains monthly public use figures for national parks.
contains the ParkName, Month, DayVisits, and CampTotal columns
The lodging table has the following specifications:
NOTE: The data set WORK.LODGING has 383 observations and 4 variables.
Challenge
Processing Statements Conditionally with SELECT-WHEN Groups
HOME WORK#7: