Hi,
My macro is not resolving because there is no data for that variable. I tried using data _null_ and set it as "0" values when data does not exist, but no luck. How do I set it to "0" in this situation?
proc sql;
select count(*) into :obs from g3pop;
quit;
%put obs: &obs.;
%if &obs > 0 %then %do;
proc sql noprint;
*Number/percent of subjects experiencing the events - Toxicity>=3 event;
select (strip(put(count (distinct usubjid), best.))) into :ng3a1 from g3pop where (trtn=1);
select (strip(put(&ng3a1./&trt1.*100, 2.))) into :pg3a1 from g3pop where (trtn=1);
select strip(put(&ng3a1., 5.))||' ('||strip(put(&pg3a1., 2.))||'%)' into :a2 from g3pop where (trtn=1);
select (strip(put(count (distinct usubjid), best.))) into :ng3p2 from g3pop where (trtn=2);
select (strip(put(&ng3p2./&trt2.*100, 2.))) into :pg3p2 from g3pop where (trtn=2);
select strip(put(&ng3p2., 5.))||' ('||strip(put(&pg3p2., 2.))||'%)' into :p2 from g3pop where (trtn=2);
quit;
%end;
%else %do;
data _null_;
call symput('p2','0 (0%)');
call symput('t2','0 (0%)');
call symput('a2','0 (0%)');
run;
%end;
Put this code before your Proc Report:
%GLOBAL p2;
%IF %BQUOTE(&p2) = %BQUOTE() %THEN
DO;
%LET p2 = 0;
END;
Jim
P.S. The second %BQUOTE isn't, strictly speaking, necessary, but I like it just for code readability. Note that there is NOT a space between the parentheses in the second %BQUOTE.
Put this code before your Proc Report:
%GLOBAL p2;
%IF %BQUOTE(&p2) = %BQUOTE() %THEN
DO;
%LET p2 = 0;
END;
Jim
P.S. The second %BQUOTE isn't, strictly speaking, necessary, but I like it just for code readability. Note that there is NOT a space between the parentheses in the second %BQUOTE.
The simplest way would be to add
%let p2=0 (0%);
%let t2=0 (0%);
%let a2=0 (0%);
before the proc sql. Then the value gets overwritten if available.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.