Hi, please help me with the code for the following problem.
Create a temporary SAS table (I named it sportoutput), read in the worksheet (Sport_List)from the library. Subset the data for a given sport of your choice and use a macro variable to specify the sport. Also, subset data where Sport is Football, Soccer, Basketball or Table Tennis.
Here is what I have so far:
data sportoutput;
set Sport_List;
run;
%Let Sport=Basketball;
proc print data=Sport_List;
where Sport="Basketball";
run;
Thank you so much!
The way you point to the excel worksheet is wrong. You must define a library. Read your course notes again.
/*This subsets data where Sport is Football, Soccer, Basketball or Table Tennis*/
data Sport_List_Football Sport_List_Soccer Sport_List_Basketball Sport_List_Table_Tennis;
set Sport_List;
if Sport="Football" then output Sport_List_Football;
if Sport="Soccer" then output Sport_List_Soccer;
if Sport="Basketball" then output Sport_List_Basketball;
if Sport="Table Tennis" then output Sport_List_Table_Tennis;
run;
PRINT only displays your data, subset your data means create a new dataset with certain, specific, records from the main data set.
Your use of macro variables is incorrect.
Here's a tutorial on filtering data:
And here's a tutorial on macros/macro variables:
https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/
This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it 🙂 https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.