Dear,
One of support helped me in my pgm. I am getting error in my pgm when I ran macro one below. It is giving me error in &title3 statement. Please help. Thanks.
%let gmvar_asat = %str((Population)) ;
%let gmvar_subtitle = %str(Population| Phases(adjuvant and Adjuvant Phases));
%let title_1=%str(Between-Treatment Comparisons in Adverse Events);
%let subtitle=&gmvar_subtitle.|&gmvar_asat.;
data _null_;
length item $1000;
%* Create Macro variables Title1-Title# to hold the title and subtitle rows *;
title_number = 0;
item = "&title_1." ;
title_number=title_number + 1;
call symput("title" || compress(put(title_number,8.)), compbl(item) );
temp_subtitle=trim(left("%nrbquote(&subtitle)"));
_sindex = 1 ;
do while(lengthn(scan(temp_subtitle,_sindex,"|")) > 0);
title_number=title_number + 1;
item=trim(left(scan(temp_subtitle,_sindex,"|")));
call symput("title" || compress(put(title_number,8.)), trim(left(item)) );
output;
_sindex=_sindex+1;
end;
run;
%macro one;
data two;
title1= '&title1.';
%if %str(&title2.)=%str( ) %then %do; title2 ="one"; %let _ttln=2; %end;
%else %if %str(&title4.)=%str( ) %then %do;title4 ="two"; %let _ttln=3 ; %end;
%else %if %str(&title3.)=%str( ) %then %do;title3 ="three"; %let _ttln=4 ; %end;
%else %do; title2 ="&title2.";title3 ="&title3."; title4 ="&title4.";title5 ="five"; %let _ttln=5; %end;
run;
%mend;
%one;
What error are you getting? Show us the relevant parts of the SASLOG. Click on the {i} icon and paste the relevant parts of the SASLOG into that window.
Thank you very much for quick help. The following errors i am seeing. Thank you
ERROR: Required operator not found in expression: &title3.=
ERROR: The macro ONE will stop executing.
For conditions with strings containing blanks, use double quotes:
%macro one;
data two;
title1= '&title1.';
%if "%str(&title2.)"="%str( )" %then %do; title2 ="one"; %let _ttln=2; %end;
%else %if "%str(&title4.)"="%str( )" %then %do;title4 ="two"; %let _ttln=3 ; %end;
%else %if "%str(&title3.)"="%str( )" %then %do;title3 ="three"; %let _ttln=4 ; %end;
%else %do; title2 ="&title2.";title3 ="&title3."; title4 ="&title4.";title5 ="five"; %let _ttln=5; %end;
run;
%mend;
%one;
but I see no reason for doing this in convoluted macro code, just a data step will do:
data two;
title1= "&title1.";
if "&title2." = "" then title2 ="one";
else if "&title4." = "" then title4 ="two";
else if "&title3." = "" then title3 ="three";
else do;
title2 = "&title2.";
title3 = "&title3.";
title4 = "&title4.";
title5 = "five";
end;
run;
although the logic escapes me anyway.
Thank you very much. It worked.
@Kurt_Bremser wrote:
For conditions with strings containing blanks, use double quotes:
%macro one; data two; title1= '&title1.'; %if "%str(&title2.)"="%str( )" %then %do; title2 ="one"; %let _ttln=2; %end; %else %if "%str(&title4.)"="%str( )" %then %do;title4 ="two"; %let _ttln=3 ; %end; %else %if "%str(&title3.)"="%str( )" %then %do;title3 ="three"; %let _ttln=4 ; %end; %else %do; title2 ="&title2.";title3 ="&title3."; title4 ="&title4.";title5 ="five"; %let _ttln=5; %end; run; %mend; %one;
Using double quotes in this context is not recommended. I think all that is needed is the proper execution time quoting function. I like SUPERQ it works as I expect in most situations.
I do agree that the entire macro part is unnecessary in this application.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.