I must preface my question by saying I’m a beginner level SAS user and have not worked with macros much. I’ve read up on some materials relating to macros but I can’t find specific examples related to what I’m working on. I need to run several proc sql statements and data steps based on a specific category name within a list. I’ve written my code to create a macro where I have to enter the specific category then run the code. Is there a way to run the code automatically for the entire list of categories and then create separate outputs for them without having to type in the category each time? I’ve seen some info about %DO loops in a macro statement but I’m not sure if this is what I should use. I’ve included a sample of the code I’ve written with a basic macro. Is there a way to do this?
%let catg = 'BEVERAGES';
%let catgdesc = "Beverages";
%SYSLPUT catg = &catg;
%SYSLPUT catgdesc = &catgdesc;
rsubmit;
proc sql;
create table skuinfo1 as
select sku, major, minor, category, sub_category
from skuinfo
order by 6;
quit;
endrsubmit;
rsubmit;
data skuinfo2;
set skuinfo1;
category = category;
if category in (&catg) then do; major = 999; end;
if major = 999 then do; category = &catgdesc; end;
run;
proc print data = skuinfo2 (obs=100);
where major = 999;
run;
endrsubmit;
rsubmit;
proc sql;
create table skus as
select *
from skuinfo2
where category in (&catgdesc.);
quit;
proc print data = skus (obs=2);
run;
endrsubmit;