SAS logo

Activities and Practices (with Solutions) for SAS® Programming 1: Essentials


Course Code: EPG1V2, prepared date: September 12, 2023
Copyright © SAS Institute Inc., Cary, NC, USA. All rights reserved.

 

Setting Up Your Practice Files (REQUIRED)

To complete the activities, demos, and practices in this course, you must access SAS software and set up your practice files.

Using the Hands-On Lab

The Hands-On Lab already has the course files loaded for you. All you have to do is launch the lab and start using SAS Studio.

Instructions for using the Hands-On Lab

Using SAS OnDemand for Academics

Setup instructions for SAS OnDemand for Academics

Using your own SAS software

Start your SAS software. Click Open next to the SAS software interface you have, and follow the instructions to set up your data.

Setup Instructions for SAS Studio

Setup Instructions for SAS Enterprise Guide

Setup Instructions for SAS Windowing Environment


Lesson 01

SAS® Programming 1: Essentials
Lesson 01, Section 2 Practice Using SAS Software


The following practices guide you through a series of steps to help you get familiar with programming in SAS software. You only have to do one. Open the practice for the software that you used when you set up your practice files in the Course Overview.

Note
: SAS provides access to SAS Studio only. The SAS Enterprise Guide option is for students who already have access to their own SAS Enterprise Guide software.

Exploring SAS Studio

Exploring SAS Enterprise Guide

SAS® Programming 1: Essentials
Lesson 01, Section 3 Activity

Open p101a03.sas from the activities folder and perform the following tasks:

  1. View the code. How many steps are in the program?

  1. How many statements are in the PROC PRINT step?

  1. How many global statements are in the program?

  1. Run the program and view the log. How many observations were read by the PROC PRINT step?

SAS® Programming 1: Essentials
Lesson 01, Section 3 Activity

Open p101a04.sas from the activities folder and perform the following tasks:

  1. Format the program to improve the spacing. What syntax error is detected?

  1. Fix the error and run the program.

  1. Read the log and identify any additional syntax errors. Correct the syntax errors and format the program again. Add a comment to describe the changes that you made to the program.

  1. Run the program and examine the log and results. How many rows are in the canadashoes data?

Lesson 02

SAS® Programming 1: Essentials
Lesson 02, Section 1 Activity

Navigate to the location of your course data:

  • In SAS Studio, open your EPG1V2/data folder.
  • In Enterprise Guide, select File > Open > Data. In the navigation panel, expand Servers> Local > Files.
  1. Double-click the storm_summary.sas7bdat SAS table to view it. How are missing character and numeric values represented in the data?

  1. Click the Table Properties tool above the storm_summary table to view the table and column attributes. Examine the length of the Basin column. Could East Pacific be properly stored as a data value in the Basin column?

SAS® Programming 1: Essentials
Lesson 02, Section 1 Activity

Open a new program window and perform the following tasks:

  1. Write a PROC CONTENTS step to generate a report of the storm_summary.sas7bdat table.
    • SAS Studio: Specify the path to your EPG1V2/data folder and the full name of the table.
    • Enterprise Guide: Specify &path and the full name of the table.

  1. How many observations are in the table?

  1. How is the table sorted?

SAS® Programming 1: Essentials
Lesson 02, Section 2 Activity: Create a Library for This Course (REQUIRED)

Assign a Library for This Course

Follow the steps for the software you are using to assign a library named PG1 that reads the SAS tables for this course.

SAS Studio

  1. Select New > SAS Program or press F4 to open a new program window.

  2. Type or copy and paste the line of code shown below into the Code tab. Replace FILEPATH with the full path to your EPG1V2/data folder in SAS Studio. If you don't know the path, open the Files and Folders panel, and expand EPG1V2. Right-click the data folder and select Properties. You can copy the path from the Location box.
  3. libname pg1 "FILEPATH";
  4. Run the code and check the log. You should see a note in the log that says the Libref PG1 was successfully assigned with information about the engine and physical name.

  5. Select the Code tab and click Save Program.

  6. For Location, select the EPG1V2 folder. Name the program libname.sas and click Save. Replace the file if it already exists.

SAS Enterprise Guide

  1. In the Project Tree, select Autoexec to make it the active process flow. Select File > New > Program to open a new program window.

  2. In the code shown below, &path is a macro variable that provides the path to a temporary location where you can store files. This macro variable was created when you set up your course files and is created each time you run the Autoexec process flow. You will learn more about macro variables later in this course. The path that this macro variable stores is the path to a temporary folder on the server. We use this temporary folder because it works in all SAS Enterprise Guide environments.
  3. libname pg1 "&path";
  4. Copy the LIBNAME statement into the Program window. Run the code and check the log. You should see a note that the libref PG1 refers the same physical library as Work and a note that the libref PG1 was successfully assigned.

  5. In the Project Tree, right click the Program icon and select Rename. Type libname.sas and press Enter.

  6. Select File > Save Project.

SAS® Programming 1: Essentials
Lesson 02, Section 2 Activity

Perform the following tasks in your SAS software:

  1. Open a new program window.

  2. Write a LIBNAME statement to create a library named NP that reads np_info.xlsx in the course data as follows:
    • SAS Studio: Specify the full path to your EPG1V2/data folder and the complete file name.
    • Enterprise Guide: Specify &path and the complete file name.

  3. Run the LIBNAME statement.

  4. Navigate to your list of libraries and open the NP library. How many tables are there in the NP library?

  1. Write an OPTIONS statement to ensure that column names follow SAS naming conventions.

  2. Write a PROC CONTENTS step to read the Parks table in the NP library.

  3. Add a LIBNAME statement after PROC CONTENTS to clear the NP library.

  4. Run the program and examine the log. Which column names have been modified to follow SAS naming conventions?

SAS® Programming 1: Essentials
Lesson 02, Section 3 Activity

Perform the following tasks in your SAS software:

  1. Open a new program editor window and copy and paste this code into the editor:

    proc import datafile="FILEPATH/storm_damage.tab"
                dbms=tab out=storm_damage_tab;
    run; 
  2. Edit FILEPATH as follows:
    • SAS Studio: Replace FILEPATH with the path to your EPG1V2/data folder.
    • Enterprise Guide: Replace FILEPATH with &path.

  3. This program imports a tab-delimited file. Run the program twice and carefully read the log. What is different about the second submission?

  1. Fix the program and rerun it to confirm that the import is successful.

SAS® Programming 1: Essentials
Lesson 02, Section 3

Level 1 Practice: Importing Excel Data from a Single Worksheet

Create a table that contains a copy of the data that is in an Excel workbook. The Excel workbook contains a single worksheet.

  1. Open p102p01.sas from the practices folder.

    • Complete the PROC IMPORT step to read eu_sport_trade.xlsx.
    • Create a SAS table named eu_sport_trade and replace the table if it exists.

    Solution:

    Replace FILEPATH with the path to your EPG1V2/data folder. If you are using Enterprise Guide, replace FILEPATH with &path.
    proc import datafile="FILEPATH/eu_sport_trade.xlsx"
                dbms=xlsx
                out=eu_sport_trade
                replace;
    run;

  2. Modify the PROC CONTENTS code to display the descriptor portion of the eu_sport_trade table.

    Solution:

    proc contents data=eu_sport_trade;
    run;

  3. Submit the program, and then view the output data and the results. How many variables are in the eu_sport_trade table?

    Solution:

    The table has six variables: Amt_Export, Amt_Import, Country, Geo_Code, Sport_Product, and Year.

SAS® Programming 1: Essentials
Lesson 02, Section 3

Level 2 Practice: Importing Data from a CSV File

Create a table from a comma-delimited CSV file.

  1. Create a new program.

    • Write a PROC IMPORT step to read the np_traffic.csv file and create the traffic SAS table.
    • Add a PROC CONTENTS step to view the descriptor portion of the newly created table.
    • Submit the program.

    Solution:

    Replace FILEPATH with the path to your EPG1V2/data folder. If you are using Enterprise Guide, replace FILEPATH with &path.
    proc import datafile="FILEPATH/np_traffic.csv"
                dbms=csv
                out=traffic
                replace;
    run;
    
    proc contents data=traffic;
    run;

  2. Examine the data interactively. Scroll down to row 37. Notice that the values for ParkName and TrafficCounter seem to be truncated.

    Solution:

    The value shown for ParkName is City of Roc and the value shown for TrafficCounter is TRAFFIC COUNT AT CIRCLE CREEK.

  3. Modify the program to resolve this issue. Submit the program and verify that ParkName and TrafficCounter are no longer truncated.

    Solution:

    Replace FILEPATH with the path to your EPG1V2/data folder. If you are using Enterprise Guide, replace FILEPATH with &path.
    proc import datafile="FILEPATH/np_traffic.csv"
                dbms=csv
                out=traffic
                replace;
        guessingrows=max;
    run;
    
    proc contents data=traffic;
    run;
    The value of ParkName is City of Rocks NRES and the value of TrafficCounter is TRAFFIC COUNT AT CIRCLE CREEK ENTRANCE.

SAS® Programming 1: Essentials
Lesson 02, Section 3

Challenge Practice: Importing Data with a Specific Delimiter

Create a table from np_traffic.dat. The values in the text file are delimited with a pipe (that is, a vertical bar).

  1. Open the SAS Procedures Guide and go to the documentation for the IMPORT Procedure. Review the syntax and examples to determine how to read a file that is delimited with a specific symbol.


  2. Use PROC IMPORT to import the np_traffic.dat file and create the temporary traffic2 SAS table. Submit the program and view the output data. How many columns are in the table?

    Solution:

    Replace FILEPATH with the path to your EPG1V2/data folder. If you are using Enterprise Guide, replace FILEPATH with &path.
    proc import datafile="FILEPATH/np_traffic.dat"
                dbms=dlm
                out=traffic2
                replace;
        guessingrows=3000;
        delimiter="|";
    run;
    The traffic2 table contains 7 columns and 2784 rows.

Lesson 03

SAS® Programming 1: Essentials
Lesson 03, Section 1

Level 1 Practice: Exploring Data with Procedures

The pg1.np_summary table contains public use statistics from the National Park Service. Use the PRINT, MEANS, UNIVARIATE, and FREQ procedures to explore the data for possible inconsistencies.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open p103p01.sas from the practices folder.

    • Complete the PROC PRINT statement to list the first 20 observations in pg1.np_summary.
    • Add a VAR statement to include only the following variables: Reg, Type, ParkName, DayVisits, TentCampers, and RVCampers.
    • Highlight the step and run the selected code.

    Solution:

    proc print data=pg1.np_summary(obs=20);
        var Reg Type ParkName DayVisits TentCampers RVCampers;
    run;

  2. Do you observe any possible inconsistencies in the data?

    Solution:

    Yes. The Type column has inconsistencies. Notice that national preserve locations have the code PRE and PRESERVE.

  3. Copy the PROC PRINT step and paste it at the end of the program.

    • Replace PRINT with MEANS and remove the OBS= data set option.
    • Modify the VAR statement to calculate summary statistics for DayVisits, TentCampers, and RVCampers.
    • Highlight the step and run the selected code.

    Solution:

    proc means data=pg1.np_summary;
        var DayVisits TentCampers RVCampers;
    run;

  4. What is the minimum value for tent campers? Is that value unexpected?

    Solution:

    The minimum value is zero. That value is not unexpected, because it's possible that a park had zero tent campers.

  5. Copy the PROC MEANS step and paste it at the end of the program.

    • Replace MEANS with UNIVARIATE.
    • Highlight the step and run the selected code.

    Solution:

    proc univariate data=pg1.np_summary;
        var DayVisits TentCampers RVCampers;
    run;

  6. Are there negative values for any of the columns?

    Solution:

    No.

  7. Copy the PROC UNIVARIATE step and paste it at the end of the program.

    • Replace UNIVARIATE with FREQ.
    • Replace the VAR statement with a TABLES statement to produce frequency tables for Reg and Type.
    • Highlight the step and run the selected code.

    Solution:

    proc freq data=pg1.np_summary;
        tables Reg Type;
    run;

  8. Are there any lowercase codes? Are there any codes that occur only once in the table?

    Solution:

    There are no lowercase codes. NC, NPRE, and RIVERWAYS occur once in the table.

  9. Add comments before each step to document the program. Save the program as np_validate.sas in the output folder.

    Solution:

    /*list first 20 rows*/
    proc print data=pg1.np_summary(obs=20);
        var Reg Type ParkName DayVisits TentCampers RVCampers;
    run;
    
    /*calculate summary statistics*/
    proc means data=pg1.np_summary;
        var DayVisits TentCampers RVCampers;
    run;
    
    /*examine extreme values*/
    proc univariate data=pg1.np_summary;
        var DayVisits TentCampers RVCampers;
    run;
    
    /*list unique values and frequency counts*/
    proc freq data=pg1.np_summary;
        tables Reg Type;
    run;

SAS® Programming 1: Essentials
Lesson 03, Section 1

Level 2 Practice: Using Procedures to Validate Data

The pg1.np_summary table contains information about US national parks, monuments, preserves, rivers, and seashores. Valid values and descriptions for the columns Reg and Type are as follows:

Reg Description Type Description
A Alaska NM National Monument
IM Intermountain NP National Park
MW Midwest NS National Seashore
NC National Capital PRE National Preserve
NE Northeast RVR National River
PW Pacific West    
SE Southeast    

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Create a new program.

    • Write a PROC FREQ step to produce frequency tables for the Reg and Type columns in the pg1.np_summary table.
    • Submit the step and look for invalid values.

    Solution:

    proc freq data=pg1.np_summary;
        tables Reg Type;
    run;

  2. What invalid values exist for Reg?

    Solution:

    No invalid values exist for Reg.

  3. What invalid values exist for Type?

    Solution:

    NPRE, PRESERVE, and RIVERWAYS are invalid values for Type.

  4. Write a PROC UNIVARIATE step to generate statistics for the Acres column in the pg1.np_summary table. Submit the step.

    Solution:

    proc univariate data=pg1.np_summary;
        var Acres;
    run;

  5. What are the observation numbers for the smallest park and the largest park?

    Solution:

    Smallest: Observation 78
    Largest: Observation 6

  6. View the pg1.np_summary table to identify the name and size of the smallest and largest parks.

    Solution:

    Smallest: African Burial Ground Monument, .35 acres
    Largest: Noatak National Preserve, 6,587,071.39 acres

SAS® Programming 1: Essentials
Lesson 03, Section 1

Challenge Practice: Generating Extreme Observations Output

The pg1.eu_occ table includes monthly occupancy counts for European countries between January 2004 and September 2017.

The SAS Output Delivery System (ODS) gives you options for controlling the type and format of the output that is generated by SAS code. The ODS SELECT statement is used to specify output objects for results. The ODS SELECT statement can be used to generate a report containing only the Extreme Observations output.

Note: To specify an output object, you need to know which output objects your SAS program produces. The ODS TRACE statement writes to the SAS log a trace record that includes the path, the label, and other information about each output object that your SAS program produces. You can find documentation about the ODS TRACE and ODS SELECT statements in the SAS Help Facility and in the online documentation.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Create a new program. Write a PROC UNIVARIATE step to examine Camp in the pg1.eu_occ table.

    Solution:

    proc univariate data=pg1.eu_occ;
        var camp;
    run;

  2. Add the ODS TRACE ON statement before the PROC UNIVARIATE step, and add the ODS TRACE OFF statement after the PROC UNIVARIATE step. Submit the program.

    Solution:

    ods trace on;
    proc univariate data=pg1.eu_occ;
        var camp;
    run;
    ods trace off;

  3. Examine the trace information in the SAS log. What is the name of the Extreme Observations output object?

    Solution:

    ExtremeObs

  4. Delete the ODS TRACE statements. Add an ODS SELECT statement immediately before the PROC UNIVARIATE step and provide the name of the Extreme Observation output object. Submit the program.

    Note: This method can be used with other procedures that create multiple tables (such as PROC CONTENTS) to select a portion of the output.

    Solution:

    ods select extremeobs;
    proc univariate data=pg1.eu_occ;
        var camp;
    run;

  5. How many extreme observations are listed?

    Solution:

    The five lowest and highest extreme observations are listed.

  6. Using the SAS documentation or the syntax Help in the editor, identify the option that specifies the number of extreme observations that are listed in the table. Use the option to change the number of extreme observations from five to 10. Submit the program.

    Solution:

    ods select extremeobs;
    proc univariate data=pg1.eu_occ nextrobs=10;
        var camp;
    run;

SAS® Programming 1: Essentials
Lesson 03, Section 2 Activity

Open p103a02.sas from the activities folder and perform the following tasks:

  1. Uncomment each WHERE statement one at a time and run the step. Notice how the results change to include only the rows that meet the condition specified in the WHERE statement.

  2. Comment all existing WHERE statements in the program. Add a new WHERE statement to print storms that begin with Z. How many storms are included in the results?




SAS® Programming 1: Essentials
Lesson 03, Section 2 Activity

Open p103a03.sas from the activities folder and perform the following tasks:

  1. Change the value in the %LET statement from NA to SP.

  2. Run the program and carefully read the log.
    1. Which procedure did not produce a report?
    2. What is different about the WHERE statement in that step?


SAS® Programming 1: Essentials
Lesson 03, Section 2

Level 1 Practice: Filtering Rows in a Listing Report Using Character Data

The pg1.np_summary table contains public use statistics from the National Park Service. The park type codes are inconsistent for national preserves. Examine these inconsistencies by producing a report that lists any national preserve.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open p103p04.sas from the practices folder.

    • Add a WHERE statement to print only the rows where ParkName includes Preserve. ParkName contains character values, and these values are case sensitive.
    • Submit the program and view the results.

    Note: If you use double quotation marks in the WHERE statement, you receive a warning in the log. To eliminate the warning, use single quotation marks.

    Solution:

    proc print data=pg1.np_summary;
        var Type ParkName;
        where ParkName like '%Preserve%';
    run;

  2. Which codes are used for preserves?

    Solution:

    PRE, PRESERVE, and NPRE

SAS® Programming 1: Essentials
Lesson 03, Section 2

Level 2 Practice: Using Macro Variables to Subset Data in Procedures

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Create a new program.

    • Write a PROC FREQ step to analyze rows from pg1.np_species.
    • Include only rows where Species_ID starts with YOSE (Yosemite National Park) and Category equals Mammal.
    • Generate frequency tables for Abundance and Conservation_Status.

    Solution:

    proc freq data=pg1.np_species;
        tables Abundance Conservation_Status;
        where Species_ID like "YOSE%" and
              Category="Mammal";
    run;

  2. Write a PROC PRINT step to list the same subset of rows from pg1.np_species.

    • Include Species_ID, Category, Scientific_Name, and Common_Names in the report.
    • Run the program.

    Solution:

    proc print data=pg1.np_species;
        var Species_ID Category Scientific_Name Common_Names;
        where Species_ID like "YOSE%" and
              Category="Mammal";
    run;

  3. How many rows meet the two specified conditions?

    Solution:

    16

  4. Create a macro variable named ParkCode to store YOSE, and another macro variable named SpeciesCat to store Mammal. Modify the code to reference the macro variables. Submit the program and confirm that the same results are generated.

    Note
    : The macro variable values are case sensitive when they are used in a WHERE statement.

    Solution:

    %let ParkCode=YOSE;
    %let SpeciesCat=Mammal;
    
    proc freq data=pg1.np_species;
        tables Abundance Conservation_Status;
        where Species_ID like "&ParkCode%" and
              Category="&SpeciesCat";
    run;
    
    proc print data=pg1.np_species;
        var Species_ID Category Scientific_Name Common_Names;
        where Species_ID like "&ParkCode%" and
              Category="&SpeciesCat";
    run;
    The same results are generated.

  5. Change the values of the macro variables to ZION (Zion National Park) and Bird. Submit the program.

    Solution:

    %let ParkCode=ZION;
    %let SpeciesCat=Bird;
    
    proc freq data=pg1.np_species;
        tables Abundance Conservation_Status;
        where Species_ID like "&ParkCode%" and
              Category="&SpeciesCat";
    run;
    
    proc print data=pg1.np_species;
        var Species_ID Category Scientific_Name Common_Names;
        where Species_ID like "&ParkCode%" and
              Category="&SpeciesCat";
    run;

  6. How many rows meet the two specified conditions?

    Solution:

    46

SAS® Programming 1: Essentials
Lesson 03, Section 2

Challenge Practice: Eliminating Case Sensitivity in WHERE Conditions

Character comparisons in a WHERE statement are case sensitive. Use SAS functions to make comparisons case insensitive.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open the pg1.np_traffic table. Notice that the case of Location values is inconsistent.


  2. Write a PROC PRINT step that lists ParkName, Location, and Count. Print rows where Count is not equal to 0 and Location includes MAIN ENTRANCE. Submit the program. Use the log to confirm that 38 rows are listed.

    Note: If you use double quotation marks in the WHERE statement, you receive a warning in the log. To eliminate the warning, use single quotation marks.

    Solution:

    proc print data=pg1.np_traffic;
        var ParkName Location Count;
        where Count ne 0 and Location like '%MAIN ENTRANCE%';
    run;

  3. The UPCASE function can be used to eliminate case sensitivity in character WHERE expressions. Use the UPCASE function on the Location column to include any case of MAIN ENTRANCE. Submit the program and verify that 40 rows are listed.

    UPCASE(column)

    Note: The UPCASE function in a WHERE statement does not permanently convert the values of the column to uppercase.

    Solution:

    proc print data=pg1.np_traffic;
        var ParkName Location Count;
        where Count ne 0 and upcase(Location) like '%MAIN ENTRANCE%';
    run;

SAS® Programming 1: Essentials
Lesson 03, Section 3 Activity

  1. Go to support.sas.com/documentation.

  2. Look up the Zw.d format.

  3. What does the format do?


SAS® Programming 1: Essentials
Lesson 03, Section 3 Activity

Open p103a05.sas from the activities folder and perform the following tasks:

  1. Highlight the PROC PRINT step and run the selected code. Notice how the values of Lat, Lon, StartDate and EndDate are displayed in the report.


  2. Change the width of the DATE format to 7 and run the PROC PRINT step. How does the display of StartDate and EndDate change?

  1. Change the width of the DATE format to 11 and run the PROC PRINT step. How does the display of StartDate and EndDate change?

  1. Highlight the PROC FREQ step and run the selected code. Notice the report includes the number of storms for each StartDate.


  2. Add a FORMAT statement to apply the MONNAME. format to StartDate and run the PROC FREQ step. How many rows are in the report?

SAS® Programming 1: Essentials
Lesson 03, Section 4 Activity

Open p103a06.sas from the activities folder and perform the following tasks:

  1. Modify the OUT= option in the PROC SORT statement to create a temporary table named storm_sort.

  2. Complete the WHERE and BY statements to answer the following question: Which storm in the North Atlantic Basin (NA or na) had the strongest MaxWindMPH?


SAS® Programming 1: Essentials
Lesson 03, Section 4

Level 1 Practice: Sorting Data and Creating an Output Table

Create the np_sort table that contains data for national parks. Sort the data by regional code and decreasing numbers of daily visitors.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open p103p08.sas from the practices folder.

    • Modify the PROC SORT step to read pg1.np_summary and create a temporary, sorted table named np_sort.
    • Add a BY statement to order the data by Reg and descending DayVisits values.
    • Add a WHERE statement to select Type equal to NP.
    • Submit the program and view the output data.

    Solution:

    proc sort data=pg1.np_summary out=np_sort;
        by Reg descending DayVisits;
        where Type="NP";
    run;

  2. How many rows are included in the np_sort table?

    Solution:

    51

SAS® Programming 1: Essentials
Lesson 03, Section 4

Level 2 Practice: Sorting Data to Remove Duplicate Rows

The pg1.np_largeparks table contains gross acreage for large national parks. There are duplicate rows for some locations.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open and review the pg1.np_largeparks table. Notice that there are exact duplicate rows for some parks.


  2. Create a new program.

    • Write a PROC SORT step that creates two tables (park_clean and park_dups), and removes the duplicate rows.
    • Submit the program and view the output data.

    Solution:

    proc sort data=pg1.np_largeparks
    		  out=park_clean
    		  dupout=park_dups
    		  nodupkey;
        by _all_;
    run;

  3. How many rows are included in the park_dups table?

    Solution:

    30

SAS® Programming 1: Essentials
Lesson 03, Section 4

Challenge Practice: Creating a Lookup Table from a Detailed Table

The pg1.eu_occ table includes multiple rows from each country code and country name. Create a lookup table that includes a single row for each country code and name.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Create a new program.

    • Write a PROC SORT step to sort pg1.eu_occ and create an output table named countrylist.
    • Remove duplicate key values.
    • Sort by Geo and then Country.
    • Submit the program and view the output data.

    Solution:

    proc sort data=pg1.eu_occ out=countryList 
              nodupkey;
        by Geo Country;
    run;

  2. What are the values of Geo and Country in row 1? How many columns are included in the table?

    Solution:

    The value of Geo is AT and the value of Country is Austria. Six columns are included.

  3. To read only Geo and Country from the pg1.eu_occ table, you can use the KEEP= data set option. Add the KEEP= option immediately after the input table and list Geo and Country. Submit the program and verify that only one row per country is included.

    data-set(KEEP=varlist)

    Solution:

    proc sort data=pg1.eu_occ(keep=geo country) out=countryList 
              nodupkey;
        by Geo Country;
    run;

Lesson 04

SAS® Programming 1: Essentials
Lesson 04, Section 1 Activity

In your SAS software, open a new program window and perform the following tasks:

  1. Write a DATA step that reads the pg1.storm_summary table and creates an output table named Storm_cat5. Note: If you are using SAS Studio, try creating storm_cat5 as a permanent table in the EPG1V2/output folder.

  2. Include only Category 5 storms (MaxWindMPH greater than or equal to 156) with StartDate on or after 01JAN2000.

  3. Add a statement to include the following columns in the output data: Season, Basin, Name, Type, and MaxWindMPH.

  4. How many Category 5 storms have there been since January 1, 2000?




SAS® Programming 1: Essentials
Lesson 04, Section 1

Level 1 Practice: Creating a SAS Table

The pg1.eu_occ SAS table contains monthly occupancy rates for European countries from January 2004 through September 2017.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open the pg1.eu_occ table and examine the column names and values.


  2. Open p104p01.sas from the practices folder.

    • Modify the code to create a temporary table named eu_occ2016 and read pg1.eu_occ.
    • Complete the WHERE statement to select only the stays that were reported in 2016. Notice that YearMon is a character column and the first four positions represent the year.
    • Complete the FORMAT statement to apply the COMMA17. format to the Hotel, ShortStay, and Camp columns.
    • Complete the DROP statement to exclude Geo from the output table.
    • Submit the program and view the output data.
    • Confirm that there are 348 rows in the eu_occ2016 table.

    Solution:

    data eu_occ2016;
        set pg1.eu_occ;
        where YearMon like "2016%";
        format Hotel ShortStay Camp comma17.;
        drop geo;
    run;
    		

SAS® Programming 1: Essentials
Lesson 04, Section 1

Level 2 Practice: Subsetting by Multiple Conditions and Creating a Sorted SAS Table

The np_species table includes one row for each species that is found in each national park.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Create a new program.

    • Write a DATA step to read the pg1.np_species table and create a new table named fox.
      Note: If you are using SAS Studio, try creating fox as a permanent table in the EPG1V2/output folder.

    • Include only the rows where Category is Mammal and Common_Names includes Fox in any case.

    • Exclude the Category, Record_Status, Occurrence, and Nativeness columns.

    • Run the program.

    Solution:

    * if you are creating a permanent table, you must submit a LIBNAME statement and then reference out.fox;
    * libname out "path-to-EPG1V2/output";
    
    data fox;
        set pg1.np_species;
        where Category='Mammal' and upcase(Common_Names) like '%FOX%';  
        drop Category Record_Status Occurrence Nativeness;
    run;
    		

  2. Notice that Fox Squirrels are included in the output table. Add a condition in the WHERE statement to exclude rows that include Squirrel. Submit the program and verify the results.

    Solution:

    data fox;
        set pg1.np_species;
        where Category='Mammal' and upcase(Common_Names) like '%FOX%' 
            and upcase(Common_Names) not like '%SQUIRREL%';    
        drop Category Record_Status Occurrence Nativeness;
    run;
    		

  3. Sort the fox table by Common_Names.

    Solution:

    data fox;
        set pg1.np_species;
        where Category='Mammal' and upcase(Common_Names) like '%FOX%' 
            and upcase(Common_Names) not like '%SQUIRREL%';    
        drop Category Record_Status Occurrence Nativeness;
    run;
    
    proc sort data=fox;
        by Common_Names;
    run;
    		

  4. What is the value of Common_Names in row one?

    Solution:

    Arctic Fox

SAS® Programming 1: Essentials
Lesson 04, Section 1

Challenge Practice: Creating a SAS Table Using Macro Variables

The np_species table includes one row for each species that is found in each national park.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Write a new program that creates a temporary table named mammal that includes only the mammals from the pg1.np_species table. Do not include Abundance, Seasonality, or Conservation_Status in the output table.

    Solution:

    data mammal;
        set pg1.np_species;
        where Category="Mammal";
        drop Abundance Seasonality Conservation_Status;
    run;		

  2. Use PROC FREQ to determine how many mammal species there are for each unique value of Record_Status. Submit the program.

    Solution:

    proc freq data=mammal;
        tables Record_Status; 
    run;		

  3. What percentage of mammal species have a Record_Status value of Approved?

    Solution:

    90.63%

  4. Modify the program to use a macro variable in place of the value Mammal so you can analyze other values of Category. Change the macro variable value to Bird and run the program.

    Solution:

    %let cat=Bird;
    
    data &cat;
        set pg1.np_species;
        where Category="&cat";
        drop Abundance Seasonality Conservation_Status;
    run;
    
    proc freq data=&cat;
        tables Record_Status;
    run;
    		

  5. What is the overall frequency of Bird species and how many are approved?

    Solution:

    The overall frequency is 2141, with 2060 approved.

SAS® Programming 1: Essentials
Lesson 04, Section 2 Activity

Open p104a04.sas from the activities folder and perform the following tasks:

  1. Add an assignment statement to create StormLength that represents the number of days between EndDate and StartDate plus 1.

  2. Run the program. In 1980, how long did the storm named Agatha last?




SAS® Programming 1: Essentials
Lesson 04, Section 2 Activity

Open p104a05.sas from the activities folder and perform the following tasks:

  1. Open the pg1.storm_range table and examine the columns. Notice that there are four wind measurements for each storm.

  2. Create a new column named WindAvg that is the mean of wind1, wind2, wind3, and wind4.

  3. Create a new column WindRange that is the range of wind1, wind2, wind3, wind4.

  4. Run the program and view the data. What are the WindAvg and WindRange values in row 1?


SAS® Programming 1: Essentials
Lesson 04, Section 2 Activity

Open p104a06.sas from the activities folder and perform the following tasks:

  1. Add a WHERE statement that uses the SUBSTR function to include rows where the second letter of Basin is P (Pacific ocean storms).

  2. Run the program and view the log and data. How many storms were in the Pacific basin?




SAS® Programming 1: Essentials
Lesson 04, Section 2

Level 1 Practice: Creating New Columnns

Create a new table named np_summary_update from pg1.np_summary and create the new columns SqMiles and Camping.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open p104p04.sas from the practices folder.

    • Create a new column named SqMiles by multiplying Acres by .0015625.
    • Create a new column named Camping as the sum of OtherCamping, TentCampers, RVCampers, and BackcountryCampers.
    • Format SqMiles and Camping to include commas and zero decimal places.
    • Modify the KEEP statement to include the new columns.
    • Submit the program.

    Solution:

    data np_summary_update;
        set pg1.np_summary;
        keep Reg ParkName DayVisits OtherLodging Acres SqMiles Camping;
        SqMiles=Acres*.0015625;
        Camping=sum(OtherCamping,TentCampers,
                    RVCampers,BackcountryCampers);
        format SqMiles comma6. Camping comma10.;
    run;

  2. What are the values of SqMiles and Camping when ParkName is Cape Krusenstern National Monument?

    Solution:

    The value of SqMiles is 1,014 and the value of Camping is 6,375.

SAS® Programming 1: Essentials
Lesson 04, Section 2

Level 2 Practice: Creating New Columns with Character and Date Functions

The pg1.eu_occ table contains individual columns for nights spent at hotels, short-stay accommodations, or camps for each year and month. The YearMon column is character.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Write a DATA step to create a temporary table named eu_occ_total that is based on the pg1.eu_occ table.

    • Create the following new columns:
      • Year: the four-digit year extracted from YearMon
      • Month: the two-digit month extracted from YearMon
      • ReportDate: the first day of the reporting month
        Note: Use the MDY function and the new Year and Month columns
      • Total: the total nights spent at any establishment
    • Format Hotel, ShortStay, Camp, and Total with commas. Format ReportDate to display the values in the form JAN2018.
    • Keep Country, Hotel, ShortStay, Camp, ReportDate, and Total in the new table.
    • Submit the program and view the output data.

    Solution:

    data eu_occ_total;
        set pg1.eu_occ;
        Year=substr(YearMon,1,4);
        Month=substr(YearMon,6,2);
        ReportDate=MDY(Month,1,Year);
        Total=sum(Hotel,ShortStay,Camp);
        format Hotel ShortStay Camp Total comma17.
               ReportDate monyy7.;
        keep Country Hotel ShortStay Camp ReportDate Total;
    run;
    

  2. What is the value of ReportDate in row one?

    Solution:

    SEP2017

SAS® Programming 1: Essentials
Lesson 04, Section 2

Challenge Practice: Creating a New Column with the SCAN Function

Access SAS Help to learn about the SCAN function.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Create a new program.

    • Create a new temporary table named np_summary2 that is based on pg1.np_summary.
    • Use the SCAN function to create a new column named ParkType that is the last word in the ParkName column. Use a negative number for the second argument to count words from right to left in the character string.
    • Keep Reg, Type, ParkName, and ParkType in the output table.
    • Submit the program and view the output data.

    Solution:

    data np_summary2;
        set pg1.np_summary;
        ParkType=scan(parkname,-1);
        keep Reg Type ParkName ParkType;
    run;
    

  2. What is the value of ParkType in row four?

    Solution:

    Preserve

SAS® Programming 1: Essentials
Lesson 04, Section 3 Activity

Open p104a07.sas from the activities folder and perform the following tasks:

  1. Add the ELSE keyword to test conditions sequentially until a true condition is met.

  2. Change the final IF-THEN statement to an ELSE statement. Run the code.

  3. How many storms are in PressureGroup 1?


SAS® Programming 1: Essentials
Lesson 04, Section 3 Activity

Open p104a08.sas from the activities folder and perform the following tasks:

  1. Run the program and examine the results.
    1. Why are the values in Ocean truncated?
    2. Looking at the code, what value is assigned to Ocean when Basin='na'?

  1. Modify the program to add a LENGTH statement to declare the name, type, and length of Ocean before the column is created.
  1. Add an assignment statement after the KEEP statement to convert Basin to uppercase. Run the program.

  1. Move the LENGTH statement to the end of the DATA step, just before the RUN statement. Run the program. Does it matter where the LENGTH statement is in the DATA step?

SAS® Programming 1: Essentials
Lesson 04, Section 3 Activity

Open p104a09.sas from the activities folder. Run the program. Why does the program fail?




SAS® Programming 1: Essentials
Lesson 04, Section 3

Level 1 Practice: Processing Statements Conditionally with IF-THEN/ELSE

The pg1.np_summary table contains public use statistics from the National Park Service. The values of the Type column represent park type as a code. Create a new column, ParkType, that contains full descriptive values.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open p104p07.sas from the practices folder. Submit the program and view the generated output.


  2. In the DATA step, use IF-THEN/ELSE statements to create a new column, ParkType, that is based on the value of Type.

    Type ParkType
    NM Monument
    NP Park
    NPRE, PRE, or PRESERVE Preserve
    NS Seashore
    RVR or RIVERWAYS River

    Solution:

    data park_type;
    	set pg1.np_summary;
    	length ParkType $ 8;
        if Type='NM' then ParkType='Monument';
        else if Type='NP' then ParkType='Park';
        else if Type in ('NPRE', 'PRE', 'PRESERVE') then
            ParkType='Preserve';
        else if Type in ('RVR', 'RIVERWAYS') then ParkType='River';
        else if Type='NS' then ParkType='Seashore';
    run;
    
    proc freq data=park_type;
        tables Type;
    run;

  3. Modify the PROC FREQ step to generate a frequency report for ParkType. Submit the program.

    Solution:

    data park_type;
        set pg1.np_summary;
        length ParkType $ 8;
        if Type='NM' then ParkType='Monument';
        else if Type='NP' then ParkType='Park';
        else if Type in ('NPRE', 'PRE', 'PRESERVE') then
            ParkType='Preserve';
        else if Type in ('RVR', 'RIVERWAYS') then ParkType='River';
        else if Type='NS' then ParkType='Seashore';
    run;
    
    proc freq data=park_type;
        tables ParkType;
    run;

  4. What is the frequency of Seashore?

    Solution:

    10

SAS® Programming 1: Essentials
Lesson 04, Section 3

Level 2 Practice: Processing Statements Conditionally with DO Groups

Use conditional processing to split pg1.np_summary into two tables: parks and monuments.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Write a DATA step to create two temporary tables, named parks and monuments, that are based on the pg1.np_summary table. Read only national parks or monuments from the input table. (Type is either NP or NM.)

    Solution:

    data parks monuments;
        set pg1.np_summary;
        where type in ('NM', 'NP');
    run;

  2. Create a new column named Campers that is the sum of all columns that contain counts of campers. Format the column to include commas.

    Solution:

    data parks monuments;
        set pg1.np_summary;
        where type in ('NM', 'NP');
        Campers=sum(OtherCamping, TentCampers, RVCampers,
                    BackcountryCampers);
        format Campers comma17.;
    run;

  3. When Type is NP, create a new column named ParkType that is equal to Park, and write the row to the parks table. When Type is NM, assign ParkType as Monument and write the row to the monuments table.

    Solution:

    data parks monuments;
        set pg1.np_summary;
        where type in ('NM', 'NP');
        Campers=sum(OtherCamping, TentCampers, RVCampers,
                    BackcountryCampers);
        format Campers comma17.;
        length ParkType $ 8;
        if type='NP' then do;
            ParkType='Park';
            output parks;
        end;
        else do;
            ParkType='Monument';
            output monuments;
        end;
    run;

  4. Keep Reg, ParkName, DayVisits, OtherLodging, Campers, and ParkType in both output tables. Submit the program and view the output data.

    Solution:

    data parks monuments;
        set pg1.np_summary;
        where type in ('NM', 'NP');
        Campers=sum(OtherCamping, TentCampers, RVCampers,
                    BackcountryCampers);
        format Campers comma17.;
        length ParkType $ 8;
        if type='NP' then do;
            ParkType='Park';
            output parks;
        end;
        else do;
            ParkType='Monument';
            output monuments;
        end;
        keep Reg ParkName DayVisits OtherLodging Campers ParkType;
    run;

  5. How many rows are in each table?

    Solution:

    Work.parks contains 51 rows, and work.monuments contains 63 rows.

SAS® Programming 1: Essentials
Lesson 04, Section 3

Challenge Practice: Processing Statements Conditionally with SELECT-WHEN Groups

SELECT and WHEN statements can be used in a DATA step to process code conditionally as an alternative to IF-THEN statements .

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Use SAS Help or online documentation to read about using SELECT and WHEN statements in the DATA step.


  2. Modify the following program (from the Level 2 practice) to use SELECT and WHEN statements instead of IF-THEN statements.

    When Type is NP, create a new column named ParkType that is equal to Park, and write the row to the parks table. When Type is NM, assign ParkType as Monument and write the row to the monuments table.

    data parks monuments;
        set pg1.np_summary;
        where type in ('NM', 'NP');
        Campers=sum(OtherCamping, TentCampers, RVCampers,
                    BackcountryCampers);
        format Campers comma17.;
        length ParkType $ 8;
        if type='NP' then do;
            ParkType='Park';
            output parks;
        end;
        else do;
            ParkType='Monument';
            output monuments;
        end;
        keep Reg ParkName DayVisits OtherLodging Campers ParkType;
    run;

    Solution:

    data parks monuments;
        set pg1.np_summary;
        where type in ('NM', 'NP');
        Campers=sum(OtherCamping, TentCampers, RVCampers,
                    BackcountryCampers);
        format Campers comma17.;
        length ParkType $ 8;
        select (type);
            when ('NP') do;
                ParkType='Park';
                output parks;
    		end;
    		otherwise do;
                ParkType='Monument';
                output monuments;
    		end;
        end;
        keep Reg ParkName DayVisits OtherLodging Campers ParkType;
    run;

  3. Submit the program and verify that work.parks contains 51 rows and work.monuments contains 63 rows.


Lesson 05

SAS® Programming 1: Essentials
Lesson 05, Section 1 Activity

Open p105a01.sas from the activities folder and perform the following tasks:

  1. In the program, notice that there is a TITLE statement followed by two procedures. Run the program. Where does the title appear in the output? 

  1. Add a TITLE2 statement above PROC MEANS to print a second line: Summary Statistics for MaxWind and MinPressure.

  2. Add another TITLE2 statement above PROC FREQ with this title: Frequency Report for Basin. Run the program. Which titles appear above each report?

  1. Open p105a02.sas from the activities folder. Notice that there are no TITLE statements in the code.

  2. Run the code. Does the previous title appear in the report?

SAS® Programming 1: Essentials
Lesson 05, Section 1 Activity

Open p105a03.sas from the activities folder and perform the following tasks:

  1. Modify the LABEL statement in the DATA step to label the Invoice column as Invoice Price.

  1. Run the program. Why do the labels appear in the PROC MEANS report but not in the PROC PRINT report? Fix the program and run it again.

SAS® Programming 1: Essentials
Lesson 05, Section 2 Activity

Open p105a04.sas from the activities folder and perform the following tasks:

  1. Create a temporary output table named storm_count by completing the OUT= option in the TABLES statement.
  1. Add the NOPRINT option on the PROC FREQ statement to suppress the printed report.
  1. Run the program. Which statistics are included in the output table? Which month has the highest number of storms?

SAS® Programming 1: Essentials
Lesson 05, Section 2

Level 1 Practice: Creating One-Way Frequency Reports

The pg1.np_species table provides a detailed species list for selected national parks. Use this table to analyze the categories of reported species.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Write a PROC FREQ step to analyze rows from pg1.np_species.

    • Use the TABLES statement to generate a frequency table for Category.
    • Use the NOCUM option to suppress the cumulative columns.
    • Use the ORDER=FREQ option in the PROC FREQ statement to sort the results by descending frequency.
    • Use Categories of Reported Species as the report title.
    • Submit the program and review the results.

    Solution:

    title1 "Categories of Reported Species";
    proc freq data=pg1.np_species order=freq;
        tables Category / nocum;
    run;

  2. What percent of the species are Fungi?

    Solution:

    5.30%

  3. Modify the PROC FREQ step to make the following changes:

    • Include only the rows where Species_ID starts with EVER and Category is not Vascular Plant.
      Note: EVER represents Everglades National Park.
    • Turn on ODS Graphics before the PROC FREQ step and turn off the procedure title.
    • Add the PLOTS=FREQPLOT option to display frequency plots.
    • Add in the Everglades as a second title.
    • Submit the program and review the results.

    Solution:

    ods graphics on;
    ods noproctitle;
    title1 "Categories of Reported Species";
    title2 "in the Everglades";
    proc freq data=pg1.np_species order=freq;
        tables Category / nocum plots=freqplot;
        where Species_ID like "EVER%" and 
              Category ne "Vascular Plant";
    run;
    title;

  4. Which Category value has the smallest frequency?

    Solution:

    Amphibian

SAS® Programming 1: Essentials
Lesson 05, Section 2

Level 2 Practice: Creating Two-Way Frequency Reports

The pg1.np_codelookup table is primarily used to look up a park name or park code. However, the table also includes columns for the park type and park region. Use this table to analyze the frequency of park types by the various regions.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Create a new program. Write a PROC FREQ step to analyze rows from pg1.np_codelookup.

    • Generate a two-way frequency table for Type by Region.
    • Exclude any park type that contains the word Other.
    • The levels with the most rows should come first in the order.
    • Suppress the display of column percentages.
    • Use Park Types by Region as the report title.
    • Submit the program and review the results.

    Solution:

    title1 'Park Types by Region';
    proc freq data=pg1.np_codelookup order=freq;
        tables Type*Region / nocol;
        where Type not like '%Other%';
    run;

  2. What are the top three park types based on total frequency count?

    Note: Statistics labels appear in the main table in Enterprise Guide if SAS Report is the output format.

    Solution:

    National Historic Site, National Monument, and National Park

  3. Modify the PROC FREQ step to make the following changes:

    • Limit the park types to the three that were determined in the previous step.
    • In addition to suppressing the display of column percentages, use the CROSSLIST option to display the table.
    • Add a frequency plot that groups the bars by the row variable, displays row percentages, and has a horizontal orientation.
      Note: Use SAS documentation to learn how the GROUPBY=, SCALE=, and ORIENT= options can be used to control the appearance of the plot.
    • Use Selected Park Types by Region as the report title.
    • Submit the program and review the results.

    Solution:

    title1 'Selected Park Types by Region';
    ods graphics on;
    proc freq data=pg1.np_codelookup order=freq;
        tables Type*Region /  nocol crosslist 
               plots=freqplot(groupby=row scale=grouppercent orient=horizontal);
        where Type in ('National Historic Site', 'National Monument', 'National Park');
    run;
    title;

  4. Which Region has the highest Row Percent value?

    Solution:

    The Intermountain region has the highest, with a value of 49.28%.

SAS® Programming 1: Essentials
Lesson 05, Section 2

Challenge Practice: Creating a Customized Graph of a Two-Way Frequency Table

The SGPLOT procedure can be used to create statistical graphics such as histograms and regression plots, in addition to simple graphics such as bar charts and line plots. Statements and options enable you to control the appearance of your graph and add additional features such as legends and reference lines.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open p105p03.sas from the practices folder. Highlight the first TITLE statement and PROC FREQ step, run the selected code, and examine the generated plot. The program subsets the pg1.np_codelookup table for three park types: National Historic Site, National Monument, and National Park. The plot uses a stacked layout with a horizontal orientation.


  2. To create a more customized frequency bar chart, the SGPLOT procedure can be used with the pg1.np_codelookup table. Examine the PROC SGPLOT step in the program.
    title1 'Counts of Selected Park Types by Park Region';
    proc sgplot data=pg1.np_codelookup;
        where Type in ('National Historic Site', 'National Monument', 'National Park');
        hbar region / group=type;
        keylegend / opaque across=1 position=bottomright location=inside;
        xaxis grid;
    run;
    • The HBAR statement creates a horizontal bar chart with separate bars for each Region. The GROUP= option segments each bar by the distinct values of Type.
    • The KEYLEGEND statement customizes the appearance and position of the legend.
    • The XAXIS statement adds reference lines on the horizontal axis.

  3. Use SAS Help or autocomplete prompts to look for additional options in the HBAR statement to customize the appearance of the chart.

    1. Display labels on each segment of the bars.
    2. Change the fill attributes for each bar so that the color is 50% transparent.
    3. Apply different values for the DATASKIN option to change the color effect on the bars.
    4. Submit the program and view the results.

    Solution:

    proc sgplot data=pg1.np_codelookup;
        where Type in ('National Historic Site', 'National Monument',
                       'National Park');
        hbar region / group=type seglabel
                      fillattrs=(transparency=0.5) dataskin=crisp;
        keylegend / opaque across=1 position=bottomright
                    location=inside;
        xaxis grid;
    run;
    title;

SAS® Programming 1: Essentials
Lesson 05, Section 3 Activity

Open p105a05.sas from the activities folder and perform the following tasks:
  1. Add options to specify the following statistics in the PROC MEANS output: N (count), MEAN, and MIN. Round each statistic to the nearest integer.

  2. Add a CLASS statement to group the data by Season and Ocean so statistics are calculated for each unique combination of season and ocean. Run the program.

  1. Modify the program to add the WAYS statement so that separate reports are created for Season and Ocean statistics. Run the program.
    • Which ocean had the lowest mean for minimum pressure?
    • Which season had the lowest mean for minimum pressure?

SAS® Programming 1: Essentials
Lesson 05, Section 3 Activity

Open p105a06.sas from the activities folder and perform the following tasks:

  1. Run the PROC MEANS step and compare the report and the wind_stats output data. Are the same statistics in the report and data? What do the first 5 rows in the data represent?

  1. Uncomment the WAYS statement. Delete the statistics listed in the PROC MEANS statement and add the NOPRINT option. Run the program. Notice a report is not generated and the first 5 rows from the previous table are excluded.

  1. Add the following options in the OUTPUT statement and run the program again.

       output out=wind_stats mean=AvgWind max=MaxWind;
    How many rows are in the output table?

SAS® Programming 1: Essentials
Lesson 05, Section 3 Activity

Open p105a07.sas from the activities folder. Run the program and examine the results to see examples of other procedures that analyze and report on the data.

Note: If the GMAP procedure generates a warning, modify the ESRIMAP URL= option in the SAS program by changing http to https, then resubmit the program. The map is created using the SGMAP procedure, which requires SAS 9.4M5 or later.


SAS® Programming 1: Essentials
Lesson 05, Section 3

Level 1 Practice: Producing a Descriptive Statistic Report

The pg1.np_westweather table contains weather-related information for four national parks: Death Valley National Park, Grand Canyon National Park, Yellowstone National Park, and Zion National Park. Use the MEANS procedure to analyze the data in this table.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Create a new program. Write a PROC MEANS step to analyze rows from pg1.np_westweather with the following specifications:

    • Generate the mean, minimum, and maximum statistics for the Precip, Snow, TempMin, and TempMax columns.
    • Use the MAXDEC= option to display the values with a maximum of two decimal positions.
    • Use the CLASS statement to group the data by Year and Name.
    • Use Weather Statistics by Year and Park as the report title.
    • Submit the program and review the results.

    Solution:

    title1 'Weather Statistics by Year and Park';
    proc means data=pg1.np_westweather mean min max maxdec=2;
        var Precip Snow TempMin TempMax;
        class Year Name;
    run;

  2. What is the mean TempMin in DEATH VALLEY, CA US in 2016?

    Solution:

    65.61

SAS® Programming 1: Essentials
Lesson 05, Section 3

Level 2 Practice: Creating an Output Table with Custom Columns

The pg1.np_westweather table contains weather-related information for four national parks: Death Valley National Park, Grand Canyon National Park, Yellowstone National Park, and Zion National Park. Use the MEANS procedure to analyze the data in this table.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Create a new program. Write a PROC MEANS step to analyze rows from pg1.np_westweather with the following specifications:

    • Exclude rows where values for Precip are equal to 0.
    • Analyze precipitation amounts grouped by Name and Year.
    • Create only an output table, named rainstats, with columns for the N and SUM statistics.
    • Name the columns RainDays and TotalRain, respectively.
    • Keep only those rows that are the combination of Year and Name.
    • Submit the program and view the output data.

    Solution:

    proc means data=pg1.np_westweather noprint;
        where Precip ne 0;
        var Precip;
        class Name Year;
    	ways 2;
    	output out=rainstats n=RainDays sum=TotalRain;
    run;

  2. How many rows are in work.rainstats?

    Solution:

    12

  3. Write a PROC PRINT step to print the rainstats table.

    • Suppress the printing of observation numbers, and display column labels.
    • Display the columns in the following order: Name, Year, RainDays, and TotalRain.
    • Label Name as Park Name, RainDays as Number of Days Raining, and TotalRain as Total Rain Amount (inches).
    • Use Rain Statistics by Year and Park as the report title.
    • Submit the program and review the results.

    Solution:

    title1 'Rain Statistics by Year and Park';
    proc print data=rainstats label noobs;
        var Name Year RainDays TotalRain;
        label Name='Park Name'
              RainDays='Number of Days Raining'
              TotalRain='Total Rain Amount (inches)';
    run;
    title;

  4. What is the Total Rain Amount (inches) value in row one?

    Solution:

    2.45

SAS® Programming 1: Essentials
Lesson 05, Section 3

Challenge Practice: Identifying the Top Three Extreme Values with the Output Statistics

Use the MEANS procedure to analyze the data in the pg1.np_multiyr table.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Create a new program. Write a PROC MEANS step to analyze rows from pg1.np_multiyr and create a table named top3parks with the following attributes:

    • Suppress the display of the PROC MEANS report.
    • Analyze Visitors grouped by Region and Year.
    • Drop the _FREQ_ and _TYPE_ columns from top3parks and keep only the rows that are a result of a combination of Region and Year.
    • Create a column for TotalVisitors in the output table.
    • Use the IDGROUP option on the OUTPUT statement to add additional columns with the top three maximum values of Visitors for each Region and Year.  Columns named Visitors_1, Visitors_2, and Visitors_3 should include the top 3 visitor counts. Columns named ParkName_1, ParkName_2, and ParkName_3 should include the corresponding park name. 
      Note: Use SAS Help to learn about the IDGROUP option in the OUTPUT statement.
    • Submit the program and view the output data.

    Solution:

    proc means data=pg1.np_multiyr noprint;
        var Visitors;
        class Region Year;
        ways 2;
        output out=top3parks(drop=_freq_ _type_)
               sum=TotalVisitors /*sum total visitors*/
        	   idgroup(max(Visitors) /*find the max of visitors*/
        	   out[3] /*top 3*/
        	   (Visitors ParkName)=); /*output columns for top 3 parks*/ 
    run;

  2. For the Alaska region in 2010, what was the third highest number of park visitors?

    Solution:

    188594

Lesson 06

SAS® Programming 1: Essentials
Lesson 06, Section 1 Activity: Create a Macro Variable (REQUIRED)

 

Follow the instructions for your software to create a macro variable that stores the location for output files.

SAS Studio

  1. In your EPG1V2 folder, open libname.sas.

  2. Create a macro variable named outpath that stores the filepath to your EPG1V2/output folder:
  3. %let outpath=filepath-to-output-folder; 
  4. Run the code.

  5. Check the log to be sure there are no errors, then save and close the program.

SAS Enterprise Guide

  1. In the Autoexec process flow, open the libname.sas program.

    • If you have write access to a folder on the server and you know the path to that folder, copy and paste the following %LET statement and replace FILEPATH with the path to the folder.
    • %let outpath = FILEPATH;
    • If you do not have write access to a folder on the server, copy and paste the following %LET statement that creates the outpath macro variable and stores the path to a location where you can create temporary files. Note that you will be able to run code to create output but in some cases you will not be able to view the output.
    • %let outpath = %sysfunc(pathname(work));
  2. Run the code.

  3. Check the log to be sure there are no errors, then close the program.

SAS® Programming 1: Essentials
Lesson 06, Section 1 Activity

Open p106a02.sas from the activities folder and perform the following tasks:

  1. Complete the PROC EXPORT step to read the pg1.storm_final SAS table and create a comma-delimited file named storm_final.csv. Use &outpath to provide the path to the file.

  2. Run the program and check the log to see if the records were written to the storm_final.csv file. If possible, open and view the text file.

    • SAS Studio: In your output folder, right-click storm_final.csv, and select View File as Text.

    • SAS Enterprise Guide: You can only view this file if you set outpath to a folder where you can write files. In the Servers pane, navigate to the folder location you specified for outpath. Right-click storm_final.csv and select Open.




SAS® Programming 1: Essentials
Lesson 06, Section 1 Activity

Open p106a03.sas from the activities folder and perform the following tasks:

  1. Complete the LIBNAME statement using the XLSX engine to create an Excel workbook named storm.xlsx.

  2. Modify the DATA step to write the storm_final table to the storm.xlsx file. Use &outpath to provide the path to the file.

  3. At the end of the DATA step, write a statement to clear the library.

  4. Run the program and view the log to confirm that storm.xlsx was exported with 3092 rows.

  5. If possible, open the storm.xlsx file.
    • SAS Studio: In your output folder, select storm.xlsx and click Download.
    • SAS Enterprise Guide: You can only view this file if you set outpath to a folder where you can write files. Select Open > Other and navigate to the location you specified for the outpath. Select storm_final.xlsx and click Open. Click Cancel in the Import Data window.

    How do dates appear in the storm_final worksheet?




SAS® Programming 1: Essentials
Lesson 06, Section 2 Activity

Open p106a04.sas from the activities folder and perform the following tasks:

  1. Add ODS statements to create an Excel file named pressure.xlsx. Use &outpath to provide the path to the file. Be sure to close the ODS location at the end of the program.

  2. Run the program and open the Excel file.
    • SAS Studio: In your output folder, select pressure.xlsx and click Download.
    • Enterprise Guide: Click the Results tab. Under Open with Default Application, double-click the Excel icon.

  3. Add the STYLE=ANALYSIS option in the first ODS EXCEL statement. Run the program again and open the Excel file.




SAS® Programming 1: Essentials
Lesson 06, Section 2 Activity

Open p106a05.sas from the activities folder and perform the following tasks:

  1. Run the program and open the pressure.pptx file.
    • SAS Studio: In your output folder, select pressure.pptx and click Download.
    • Enterprise Guide: Click the Results - PowerPoint tab and click Download.

  2. Modify the ODS statements to change the output destination to RTF. Change the style to sapphire.

  3. Run the program and open the pressure.rtf file.
    • SAS Studio: In your output folder, select pressure.rtf and click Download.
    • Enterprise Guide: Click the Results - RTF tab and click Download.

  4. Add the STARTPAGE=NO option in the first ODS RTF statement to eliminate the page break.

  5. Rerun the program and examine the new report.




SAS® Programming 1: Essentials
Lesson 06, Section 2

Level 1 Practice: Creating an Excel File Using ODS EXCEL

Create an Excel workbook named StormStats.xlsx that includes the results of SAS procedures. Customize the names of the Excel worksheets.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open p106p01.sas from the practices folder. Before the PROC MEANS step, add an ODS EXCEL statement to do the following:

    • Write the output file to "&outpath/StormStats.xlsx".
    • Set the style for the Excel file to snow.
    • Set the sheet name for the first tab to South Pacific Summary.

    Solution:

    ods excel file="&outpath/StormStats.xlsx"
        style=snow
        options(sheet_name='South Pacific Summary');
    proc means data=pg1.storm_detail maxdec=0 median max; class Season; var Wind; where Basin='SP' and Season in (2014,2015,2016); run; proc print data=pg1.storm_detail noobs; where Basin='SP' and Season in (2014,2015,2016); by Season; run;

  2. Turn off the procedure titles and report titles at the start of the program. Turn the procedure titles on at the end of the program.

    Solution:

    ods excel file="&outpath/StormStats.xlsx"
        style=snow
        options(sheet_name='South Pacific Summary');
    ods noproctitle;
    proc means data=pg1.storm_detail maxdec=0 median max; class Season; var Wind; where Basin='SP' and Season in (2014,2015,2016); run; proc print data=pg1.storm_detail noobs; where Basin='SP' and Season in (2014,2015,2016); by Season; run; ods proctitle;

  3. Immediately before the PROC PRINT step, add an ODS EXCEL statement to change the sheet name to Detail.

    Solution:

    ods excel file="&outpath/StormStats.xlsx"
        style=snow
        options(sheet_name='South Pacific Summary');
    ods noproctitle;
    proc means data=pg1.storm_detail maxdec=0 median max; class Season; var Wind; where Basin='SP' and Season in (2014,2015,2016); run; ods excel options(sheet_name='Detail'); proc print data=pg1.storm_detail noobs; where Basin='SP' and Season in (2014,2015,2016); by Season; run; ods proctitle;

  4. At the end of the program, add an ODS EXCEL statement to close the Excel destination.

    Solution:

    ods excel file="&outpath/StormStats.xlsx"
        style=snow
        options(sheet_name='South Pacific Summary');
    ods noproctitle;
    proc means data=pg1.storm_detail maxdec=0 median max; class Season; var Wind; where Basin='SP' and Season in (2014,2015,2016); run; ods excel options(sheet_name='Detail'); proc print data=pg1.storm_detail noobs; where Basin='SP' and Season in (2014,2015,2016); by Season; run; ods excel close; ods proctitle;

  5. Submit the program. Open the StormStats.xlsx workbook in Excel.
    • SAS Studio: In the Files and Folders panel, navigate to EPG1V2 > output. Select StormStats.xlsx and click Download.
    • Enterprise Guide: Click the Results - Excel tab and click Download.


SAS® Programming 1: Essentials
Lesson 06, Section 2

Level 2 Practice: Creating a Document with ODS RTF

Generate an RTF file that can be opened in Microsoft Word and other word processing software. The file should include the results of three procedures and use different styles to change the appearance.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open p106p02.sas from the practices folder. Modify the program with the following specifications:

    • Add an ODS statement to write the output file to &outpath/ParkReport.rtf.
    • Set the style for the output file to Journal and remove page breaks between procedure results.
    • Turn off the procedure titles at the start of the program. Turn the procedure titles on at the end of the program.
    • At the end of the program, close the ODS destination.
    • Submit the program.

    Solution:

    ods rtf file="&outpath/ParkReport.rtf" style=Journal startpage=no;
    
    ods noproctitle;
    
    title "US National Park Regional Usage Summary";
    
    proc freq data=pg1.np_final;
        tables Region /nocum;
    run;
    
    proc means data=pg1.np_final mean median max nonobs maxdec=0;
        class Region;
        var DayVisits Campers;
    run;
    
    title2 'Day Vists vs. Camping';
    proc sgplot data=pg1.np_final;
        vbar  Region / response=DayVisits;
        vline Region / response=Campers;
    run;
    title;
    
    ods proctitle;
    ods rtf close;

  2. Open the output file.
    • SAS Studio: In the Files and Folders panel, navigate to EPG1V2 > output. Select parkreport.rtf and click Download.
    • Enterprise Guide: Click the Results - RTF tab and click Download.

    The Journal style is applied to the results, but the graph is in grayscale instead of in color. Also the date and time the program ran is printed in the upper right corner of the page. Close the report.


  3. Modify your SAS program so that both tables are created using the Journal style, but the SASDOCPRINTER style is used to create the graph.

    Note: An ODS destination statement enables you to specify a style without requiring you to redefine the output file location.

    Solution:

    ods rtf file="&outpath/ParkReport.rtf" style=Journal startpage=no;
    
    ods noproctitle;
    
    title "US National Park Regional Usage Summary";
    
    proc freq data=pg1.np_final;
        tables Region /nocum;
    run;
    
    proc means data=pg1.np_final mean median max nonobs maxdec=0;
        class Region;
        var DayVisits Campers;
    run;
    
    ods rtf style=SASDocPrinter;
    
    title2 'Day Vists vs. Camping';
    proc sgplot data=pg1.np_final;
        vbar  Region / response=DayVisits;
        vline Region / response=Campers;
    run;
    title;
    
    ods proctitle;
    ods rtf close;
    

  4. Add an OPTIONS statement with the NODATE option at the beginning of the program to suppress the date and time in the RTF file. Restore the option for future submissions by adding an OPTIONS statement with the DATE option at the end of the program.

    Solution:

    ods rtf file="&outpath/ParkReport.rtf" style=Journal startpage=no;
    
    ods noproctitle;
    options nodate;
    
    title "US National Park Regional Usage Summary";
    
    proc freq data=pg1.np_final;
        tables Region /nocum;
    run;
    
    proc means data=pg1.np_final mean median max nonobs maxdec=0;
        class Region;
        var DayVisits Campers;
    run;
    
    ods rtf style=SASDocPrinter;
    
    title2 'Day Vists vs. Camping';
    proc sgplot data=pg1.np_final;
        vbar  Region / response=DayVisits;
        vline Region / response=Campers;
    run;
    title;
    
    ods proctitle;
    ods rtf close;
    options date;

  5. Submit the program. Open the new output file. Ensure that the syle for both tables is the same, but that the graph is now displayed in color. Close the report.


SAS® Programming 1: Essentials
Lesson 06, Section 2

Challenge Practice: Creating a Landscape Report with ODS PDF

Generate a PDF document in landscape orientation. Print a report and map side by side.

Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow.

  1. Open p106p03.sas from the practices folder. Run the program and examine the output. The program produces a table and a map for North Atlantic region storms in the 2016 season. Note: You must have SAS 9.4M5 to run this code.


  2. Modify the program to produce a PDF file named StormSummary.pdf in the output folder in the course files. Set the output style to Journal. Specify not to generate bookmarks in the file.

    Solution:

    ods pdf file="&outpath/StormSummary.PDF" style=Journal nobookmarkgen;
    
    title1 "2016 Northern Atlantic Storms";
    
    proc sgmap plotdata=pg1.storm_final;
        *openstreetmap;
        esrimap url='http://services.arcgisonline.com/arcgis/rest/services/World_Physical_Map';
        bubble x=lon y=lat size=maxwindmph / datalabel=name datalabelattrs=(color=red size=8);
        where Basin='NA' and Season=2016;
        keylegend 'wind';
    run;
    
    proc print data=pg1.storm_final noobs;
        var name StartDate MaxWindMPH StormLength;
        where Basin="NA" and Season=2016;
        format StartDate monyy7.;
    run;
    
    ods pdf close;
    

  3. Use SAS Help to find a SAS system option that changes the page layout to landscape.

    Solution:

    options orientation=landscape;
    ods pdf file="&outpath/StormSummary.PDF" style=Journal nobookmarkgen;
    
    title1 "2016 Northern Atlantic Storms";
    
    proc sgmap plotdata=pg1.storm_final;
        *openstreetmap;
        esrimap url='http://services.arcgisonline.com/arcgis/rest/services/World_Physical_Map';
        bubble x=lon y=lat size=maxwindmph / datalabel=name datalabelattrs=(color=red size=8);
        where Basin='NA' and Season=2016;
        keylegend 'wind';
    run;
    
    proc print data=pg1.storm_final noobs;
        var name StartDate MaxWindMPH StormLength;
        where Basin="NA" and Season=2016;
        format StartDate monyy7.;
    run;
    
    ods pdf close;

  4. Use SAS Help to learn about the ODS LAYOUT GRIDDED statement as a way that you can control the layout of multiple result objects. Force the results to be arranged in one row and two columns.

    Solution:

    options orientation=landscape;
    ods pdf file="&outpath/StormSummary.PDF" style=Journal nobookmarkgen;
    
    title1 "2016 Northern Atlantic Storms";
    
    ods layout gridded columns=2 rows=1;
    ods region;
    
    proc sgmap plotdata=pg1.storm_final;
        *openstreetmap;
        esrimap url='http://services.arcgisonline.com/arcgis/rest/services/World_Physical_Map';
        bubble x=lon y=lat size=maxwindmph / datalabel=name datalabelattrs=(color=red size=8);
        where Basin='NA' and Season=2016;
        keylegend 'wind';
    run;
    
    ods region;
    proc print data=pg1.storm_final noobs;
        var name StartDate MaxWindMPH StormLength;
        where Basin="NA" and Season=2016;
        format StartDate monyy7.;
    run;
    
    ods layout end;
    ods pdf close;

  5. Reset the system option at the end of the program so that future results have a portrait layout.

    Solution:

    options orientation=landscape;
    ods pdf file="&outpath/StormSummary.PDF" style=Journal nobookmarkgen;
    
    title1 "2016 Northern Atlantic Storms";
    
    ods layout gridded columns=2 rows=1;
    ods region;
    
    proc sgmap plotdata=pg1.storm_final;
        *openstreetmap;
        esrimap url='http://services.arcgisonline.com/arcgis/rest/services/World_Physical_Map';
        bubble x=lon y=lat size=maxwindmph / datalabel=name datalabelattrs=(color=red size=8);
        where Basin='NA' and Season=2016;
        keylegend 'wind';
    run;
    
    ods region;
    proc print data=pg1.storm_final noobs;
        var name StartDate MaxWindMPH StormLength;
        where Basin="NA" and Season=2016;
        format StartDate monyy7.;
    run;
    
    ods layout end;
    ods pdf close;
    options orientation=portrait;

  6. Submit the program. Open the StormSummary.pdf file to confirm the results.
    • SAS Studio: In the Files and Folders panel, navigate to EPG1V2 > output. Select StormSummary.pdf and click Download.
    • Enterprise Guide: Click the Results - PDF tab and click Download.

      Note: SAS Studio generates a warning in the log because the wrapper code is creating an RTF file behind the scenes. ODS LAYOUT is not supported in RTF. The warning can be ignored because it doesn't impact the PDF results.


Lesson 07

SAS® Programming 1: Essentials
Lesson 07, Section 1 Activity

Open p107a01.sas from the activities folder and run the program.

  1. What are the similarities and differences in the syntax of the two steps?

  1. Run the program. What are the similarities and differences in the results?

SAS® Programming 1: Essentials
Lesson 07, Section 1 Activity

Open p107a02.sas from the activities folder and perform the following tasks:

  1. Complete the SQL query to display Event and Cost from pg1.storm_damage. Format the values of Cost.

  2. Add a new column named Season that extracts the year from Date.

  3. Add a WHERE clause to return rows where Cost is greater than 25 billion.

  4. Add an ORDER BY clause to arrange rows by descending Cost.

  5. Run the code. Which storm had the highest cost?




SAS® Programming 1: Essentials
Lesson 07, Section 2 Activity

Open p107a03.sas from the activities folder and perform the following tasks:

  1. Define aliases for storm_summary and storm_basincodes in the FROM clause.

  2. Use one table alias to qualify Basin in the SELECT clause.

  3. Complete the ON expression to match rows when Basin is equal in the two tables. Use the table aliases to qualify Basin in the expression. Run the code.

  4. View the report. The storm_summary table includes some lowercase Basin values. Are they in the results?