Programming the statistical procedures from SAS

Need help passing a macro variable

Reply
N/A
Posts: 0

Need help passing a macro variable

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);
Regular Contributor
Posts: 169

Re: Need help passing a macro variable

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);
Ask a Question
Discussion stats
  • 1 reply
  • 63 views
  • 0 likes
  • 2 in conversation