0% found this document useful (2 votes)
1K views

Using Macro Variables To Subset Data in Procedures

This document provides steps for using macro variables to subset data in SAS procedures. It demonstrates creating macro variables to store subset criteria and referencing the macro variables in WHERE statements. The macro variables allow easily changing the subset criteria to filter the data for different subsets. It shows the techniques generate the same results for subsets of species data from national parks filtered by park code and category.

Uploaded by

rrutayisire
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (2 votes)
1K views

Using Macro Variables To Subset Data in Procedures

This document provides steps for using macro variables to subset data in SAS procedures. It demonstrates creating macro variables to store subset criteria and referencing the macro variables in WHERE statements. The macro variables allow easily changing the subset criteria to filter the data for different subsets. It shows the techniques generate the same results for subsets of species data from national parks filtered by park code and category.

Uploaded by

rrutayisire
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

8/22/2020 Steps

Print

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.

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.

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?

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.

%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;

https://vle.sas.com/pluginfile.php/800788/mod_scorm/content/268/03/epg1v203_2_p_l2.htm 1/2
8/22/2020 Steps

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.

%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?

46

Hide Solution

https://vle.sas.com/pluginfile.php/800788/mod_scorm/content/268/03/epg1v203_2_p_l2.htm 2/2

You might also like