SAS problem solving skill

Reply
Contributor
Posts: 29

SAS problem solving skill

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

Highlighted
Super User
Posts: 19,093

Re: SAS problem solving skill

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

Super User
Posts: 7,422

Re: SAS problem solving skill

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
PROC Star
Posts: 653

Re: SAS problem solving skill

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

Super User
Posts: 11,121

Re: SAS problem solving skill

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.

Community Manager
Posts: 2,889

Re: SAS problem solving skill

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

Contributor
Posts: 29

Re: SAS problem solving skill

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.

Super User
Posts: 7,422

Re: SAS problem solving skill

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)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 7 replies
  • 180 views
  • 8 likes
  • 6 in conversation