Hi everyone,
My dataset has 18 schools in total. I have a macro written to output .rtf files by school.
I'd like the macro to generate an automated file name for each school, for instance:
Profile_School of Business_&SYSDATE9.rtf
Profile_School of Engineering_&SYSDATE9.rtf
But instead, this happened:
Profile_put(int_frrpt, $intmaj.)_19SEP2019.rtf
What am I doing wrong?
My code:
proc format; value $intmaj 'BUS'='School of Business' 'ENGI'='School of Engineering'; run; %macro Run_Tabulate2 (school=); ODS RESULTS OFF; options orientation=landscape NODATE NOSTIMER NONUMBER NOBYLINE; %let schl = put(int_frrpt, $intmaj.); ods rtf file="&root.\Output\Profile_&schl._&SYSDATE9..rtf" startpage=no BODYTITLE_AUX cssstyle="&root.\style.css"; ods escapechar='^'; proc tabulate; ** Insert misc stats by school here; run; ods rtf close; %mend; %Run_Tabulate2 (school='BUS');
The macro language is just a text replacement system, so you will have the text
put(int_frrpt, $intmaj.)
inserted where you use &schl.:
Output\Profile_&schl._
thus turns into
Output\Profile_put(int_frrpt, $intmaj.)_
and since data step functions are not executed in this place, you end up with the text that surprises you.
Also, you could only resolve the text "int_frrpt", but never the contents of a variable called int_frrpt.
Change your %let to
%let schl = %sysfunc(putc(&school.,$intmaj.));
The macro language is just a text replacement system, so you will have the text
put(int_frrpt, $intmaj.)
inserted where you use &schl.:
Output\Profile_&schl._
thus turns into
Output\Profile_put(int_frrpt, $intmaj.)_
and since data step functions are not executed in this place, you end up with the text that surprises you.
Also, you could only resolve the text "int_frrpt", but never the contents of a variable called int_frrpt.
Change your %let to
%let schl = %sysfunc(putc(&school.,$intmaj.));
Thanks so much for the explanation. However when I tried to used your code, I got Profile_'BUS'_19SEP2019.rtf. Any ideas?
@lin39 wrote:
Thanks so much for the explanation. However when I tried to used your code, I got Profile_'BUS'_19SEP2019.rtf. Any ideas?
Does the format actually know how to decode the value 'BUS' instead of BUS? If not then don't include the single quotes in the value of the macro variable.
Since the macro processor is a text processor only, quotes are almost never needed. Change your macro call to
%Run_Tabulate2(school=BUS);
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.