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.  

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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