BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi, I need to pass the cat1 variable into the in statement, but the macro doesn't like the commas. how can i pass multiple verticals in the same variable?

%macro cat(cat1, cat=);

data &cat;
set lastqcomp;
where vertical in (&cat1);
run;

%mend cat;

%cat(cat1='Apparel, Accessories & Footwear','Other','Toys' cat=allvert);
1 REPLY 1
Dale
Pyrite | Level 9
This should be posted in the forum "SAS Macro Facility, Data Step and SAS Language Elements". It has nothing to do with SAS Statistical Procedures.

That said, you should be able to pass the string for cat1 by using the %str() macro quoting function.

%cat(cat1=%str('Apparel, Accessories & Footwear','Other','Toys'), cat=allvert);


I would note that your %macro statement names cat1 as a positional parameter and cat as a keyword parameter. However, your invocation shows that you intend to use cat1 as a keyword parameter. Code which is consistent for both macro definition and invocation would be:

%macro cat(cat1=, cat=);

data &cat;
set lastqcomp;
where vertical in (&cat1);
run;

%mend cat;

%cat(cat1=%str('Apparel, Accessories & Footwear','Other','Toys'), cat=allvert);

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1128 views
  • 0 likes
  • 2 in conversation