BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HitmonTran
Pyrite | Level 9

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?

 

HitmonTran_0-1623645176146.png

 
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;
1 ACCEPTED SOLUTION

Accepted Solutions
jimbarbour
Meteorite | Level 14

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.

View solution in original post

2 REPLIES 2
jimbarbour
Meteorite | Level 14

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.

ChrisNZ
Tourmaline | Level 20

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.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1537 views
  • 4 likes
  • 3 in conversation