BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
animesh123
Obsidian | Level 7


%macro carmake(Make= , Models=);
data cars;
set sashelp.cars;
where Make in (&make)and Model in (&models);
run;
%mend;

%carmake(Make= "Acura" "Audi" "BMW" "Hyundai", Models= "SUV" "Sedan");

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Last time I looked at the SASHELP.CARS data set the variable TYPE had values like "SUV" and "Sedan".

 

Model has stuff like "RSX Type S 2dr".

So expect 0 observations in the result using Model that way.

View solution in original post

4 REPLIES 4
sbxkoenk
SAS Super FREQ

Not executing? Why do you say so?

 

If I submit, I get a dataset with zero observations in return!

So, it works !

 

Koen

ballardw
Super User

Last time I looked at the SASHELP.CARS data set the variable TYPE had values like "SUV" and "Sedan".

 

Model has stuff like "RSX Type S 2dr".

So expect 0 observations in the result using Model that way.

animesh123
Obsidian | Level 7

Thaks for help my bad I have fixed the issue 

%macro carmake(Make= , Types=);
data cars;
set sashelp.cars;
where Make in (&make)and Type in (&Types);
run;
%mend;

%carmake(Make= "Acura" "Audi" "BMW" "Hyundai", Types= "SUV" "Sedan");

PaigeMiller
Diamond | Level 26

Part of the problem is that you did not follow the general recommended advice, to first create code that works properly without macro variables and without macros. Had you done that, perhaps you would have figured out the problem, and then your macro would work properly.

 

But without macro variables and without macros, your code is this

data cars;
set sashelp.cars;
where Make in ( "Acura" "Audi" "BMW" "Hyundai") and Model in ("SUV" "Sedan");
run;

 

 

which doesn't work the way you want either. It returns an empty data set.

 

So please follow the above very good advice. You need to first make this code work without macros and without macro variables, and then you should be able to make your macro work properly.

--
Paige Miller

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 387 views
  • 0 likes
  • 4 in conversation