I need to read in the number of treatment groups and the unique count associated with each treatment in a macro. This unique number of cohort will be my denominator at a later step to create an adverse event table.
proc sort data=adae out=adae_subs (keep=subject cohort) nodupkey; by subject; run;
proc freq data=adae_subs nlevels noprint;
tables cohort/out=cohortct outcum;
run;
data cohortct;
set cohortct;
rename count=cohortct;
run;
proc sql;
select distinct cohort
into :coh1 - :coh3
from cohortct;
quit;
%macro coh(coh=,num=);
data test;
set cohortct;
where cohort="&coh.";
call symputx ("cohortct&num.",COHORTCT);
run;
%mend coh;
%coh (coh=&coh1,num=a);%coh (coh=&cohb,num=b);%coh (coh=&cohc,num=c);
%put &cohortcta;%put &cohortctb;%put &cohortctc;
I get the following warning
WARNING: Apparent symbolic reference COHORTCTB not resolved.
Post the log.
Is the macro call %coh (coh=&cohb,num=b) resulting in any records in the dataset test ?
Macro variable scope. Look at the third aprameter in CALL SYMPUTX() and use it to define your macro variables as global macro variables.
You may also want to look into CALL EXECUTE.
@saslove wrote:
I need to read in the number of treatment groups and the unique count associated with each treatment in a macro. This unique number of cohort will be my denominator at a later step to create an adverse event table.
proc sort data=adae out=adae_subs (keep=subject cohort) nodupkey; by subject; run;
proc freq data=adae_subs nlevels noprint;
tables cohort/out=cohortct outcum;
run;data cohortct;
set cohortct;
rename count=cohortct;
run;
proc sql;
select distinct cohort
into :coh1 - :coh3
from cohortct;
quit;
%macro coh(coh=,num=);
data test;
set cohortct;
where cohort="&coh.";
call symputx ("cohortct&num.",COHORTCT);
run;
%mend coh;
%coh (coh=&coh1,num=a);%coh (coh=&cohb,num=b);%coh (coh=&cohc,num=c);
%put &cohortcta;%put &cohortctb;%put &cohortctc;
I get the following warning
WARNING: Apparent symbolic reference COHORTCTB not resolved.
I guess you also get a WARNING for cohb, as that macro variable is never defined in your code; I think you wanted to use coh2 instead. Same with cohc, which should be coh3.
In this statement call symputx ("cohortct&num.",COHORTCT);
COHORTCT is a variable that does not exist in your proc freq output dataset named COHORTCT
data adae_subs ;
set sashelp.class(rename=(weight=cohort));
run;
proc freq data=adae_subs nlevels noprint;
tables cohort/out=cohortct(rename=(count=cohortct)) outcum;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.