Dear,
In my pgm why the the &title1-&title4 are not resolved. I am getting errors when i ran below data _null_ step. Please help. Thank you.
%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;
put &title1.=;
put &title2.=;
put &title3.=;
put &title4.=;
run;
Once again, misunderstanding of macro timing.
The put statements are part of data step code, and so the macro PREprocessor tries to resolve the macro variables before they are created.
Use %put after the data step boundary (the run statement):
%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;
%put title1=&title1.;
%put title2=&title2.;
%put title3=&title3.;
%put title4=&title4.;
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.