BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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;
5 REPLIES 5
PaigeMiller
Diamond | Level 26

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.

 

 

--
Paige Miller
knveraraju91
Barite | Level 11

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.

Kurt_Bremser
Super User

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.

knveraraju91
Barite | Level 11

Thank you very much. It worked.

data_null__
Jade | Level 19

@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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 942 views
  • 1 like
  • 4 in conversation