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;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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