BookmarkSubscribeRSS Feed
saslove
Quartz | Level 8

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.

5 REPLIES 5
r_behata
Barite | Level 11

Post the log.

 

Is the macro call %coh (coh=&cohb,num=b) resulting in any records in the dataset test ? 

Reeza
Super User

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.


 

 

Kurt_Bremser
Super User

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.

Reeza
Super User
Should your macro calls be &cohb or &coh2?
It seems like you may be mixing counters?
ShiroAmada
Lapis Lazuli | Level 10

 

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1609 views
  • 2 likes
  • 5 in conversation