Can anyone suggest any SAS book or online resources where I can practice problem solving ? I just want to work on my problem solving skills in SAS and most of the tutorials online only explains the syntax but not problem solving. For example:I found this problem online. And I want to work on more of these. Any guideline will be highly appreciated.
below code is given
%macro subset( cust=);
proc print data= feedback;
where customer = "&cust";
run;
%mend;
This is the question-
Write a program that will programmatically call %subset for each customer value inFeedback. Note that we do not know how many unique values ofcustomer there are in the data set. Also, you cannot modify the macro %subset itself.
And this is the table
Answer questions on here and StackOveflow. You're not going to get a better sample of real world examples.
Answer problems in the various communities and practice using the SAS documentation to do so 🙂
I think I can interpret your example problem in more than one way. Input is only half the problem, if that much. Knowing exactly what the desired output should be is very important in the general problem solving process.
For example, one solution to print groups of records for each customer does not involve your macro at all.
Proc sort data=feedback;
by customer;
run;
proc print data=feedback;
by customer;
run;
So there isn't sufficient reason provided why a BY group solution would not work for that problem.
@shihabur, I'm curious where you found this particular question, as it has made an appearance here before. I agree with ballardw that it seems contrived -- why use a macro? Goes against one of @Kurt_Bremser's famous maxims.
But beyond that, I love the advice of the responders so far. I often try out the solutions that these experts share here -- it helps me to learn too.
Frankly speaking, I was asked to solve this as a problem. No idea if its from a book or if someone made it up. I wasn't looking for solution here. Rather trying to learn the thought process behind problem solving. Anyways, now that ballardw explained, it seems this is not even a good problem to begin with. I will try to follow the suggestions given here.
So you have a macro that accepts a single input parameter, and you want to run that macro for each value given in a dataset, where values can occur multiple times
- step one: get a list of values without duplicates; can be done with sort nodupkey, or select distinct in SQL
- step two: call your macro off that list; this is best done with call execute()
Hint: lists are best kept in datasets
Note that I had no idea about call execute() before I ran into the SAS Communities. It is simply not covered in the standard SAS programming courses (at least it was not in the five weeks I did when I started with SAS in '98/'99)
Try this
data _null_;
set feedback;
i=_n_;
for j=1 to i do;
call execute(%subset(cust = customer);
Run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.