BookmarkSubscribeRSS Feed
shihabur
Obsidian | Level 7

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

Screen Shot 2017-10-11 at 2.22.21 PM.png

8 REPLIES 8
Reeza
Super User

Answer questions on here and StackOveflow. You're not going to get a better sample of real world examples. 

Kurt_Bremser
Super User

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.

PeterClemmensen
Tourmaline | Level 20

Answer problems in the various communities and practice using the SAS documentation to do so 🙂

ballardw
Super User

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.

ChrisHemedinger
Community Manager

@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.  

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
shihabur
Obsidian | Level 7

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.

Kurt_Bremser
Super User

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)

Amrita_abc
Calcite | Level 5

Try this

 

data _null_;
set feedback;
i=_n_;
for j=1 to i do;
call execute(%subset(cust = customer);
Run;

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 3076 views
  • 12 likes
  • 7 in conversation