10-11-2017 02:33 PM
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
10-11-2017 03:25 PM
Exactly what @Reeza said. Solve problems presented here (you don't need to post, just create a solution for yourself), and then compare your solution to those that people like @Reeza, @Ksharp and other senior posters come up with. Often you'll be surprised and learn something new.
10-11-2017 05:49 PM
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;
proc print data=feedback;
So there isn't sufficient reason provided why a BY group solution would not work for that problem.
10-11-2017 08:16 PM
@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 @KurtBremser'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.
10-11-2017 10:34 PM
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.
10-12-2017 03:00 AM
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)