There is a question:
Create a Macro variable for Dallas in the Location variable of Data: ALL.
Use this macro variable to subset the ‘ALL’ excel data inside the proc SQL to select variables student_name,
teacher, fee, days, paid, location. Write a Proc SQL query to find the ‘average fee’ and ‘total fee’
by ‘paid’ variable for Dallas.
This data set of All is like:
Using this following Proc SQL procedure the goal is easily achieved:
Proc SQL;
Select student_name, fee, days, paid, location,
mean(fee) as avg_fee label = 'average fee',
sum(fee) as tot_fee label = 'total fee'
From All
Where location = 'Dallas' and Paid = 'Y';
Quit;
However, when I tried to use the following code to create a macro variable to subset the location variable into 'Dallas', it did not work:
Proc SQL;
Select student_name, fee, days, paid,
mean(fee) as avg_fee label = 'average fee',
sum(fee) as tot_fee label = 'total fee', location into :Dallas
From All
Where Paid = 'Y';
Quit;
Would someone like to kindly show me how I should create the macro variable so as to subset the location variable successfully?
Thank you!
Hello,
Why do you want to create a macro variable if you know you want to filter by Dallas?
Hello. Athenkosi,
This is because I have to satisfy what the instructor wants.
The question is
Create a Macro variable for Dallas in the Location variable of Data ALL.
Use this macro variable to subset the ‘ALL’ excel data inside the proc SQL to select variables student_name,
teacher, fee, days, paid, location. Write a Proc SQL query to find the ‘average fee’ and ‘total fee’
by ‘paid’ variable for Dallas.
I got it! Also, I correct a mistake:
The data set should be classified by 'Pait', not 'Paid' = 'Y'.
%let loctn = Dallas;
Proc SQL;
Select student_name, fee, days, paid, location,
mean(fee) as avg_fee label = 'average fee',
sum(fee) as tot_fee label = 'total fee'
From All
Where location = "&loctn"
Group by paid;
Quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.