Hello,
If I have the data like what follows, how do I generate one rtf file for each college automatically?
Data collegesummary;
input college $ program $ report $;
cards;
LLL Chinese Yes
LLL English No
LLL Spanish Yes
LLL Korean No
Engineering Mechanical Yes
Engineering Chemical Yes
Engineering Electrical No
;
run;
If I use ods.rtf and proc report, how can I create one rtf file for each college. One for LLL and one for engineering?
For LLL college, I have the following:
ods rtf path=&dir.
file="&dsn&sysdate..rtf" ;
proc report data=collegesummary nowd;
where college="LLL";
column program report;
define program/display;
define report/display;
run;quit;
ods rtf close;
If I have 20 colleges, I can't do it manually one by one, because I also specified other style options, some of which are specific to the rtf destination.
Thank you.
Yao
Data collegesummary;
input college $ program $ report $;
cards;
LLL Chinese Yes
LLL English No
LLL Spanish Yes
LLL Korean No
Engineering Mechanical Yes
Engineering Chemical Yes
Engineering Electrical No
;
run;
title;
%let dir = "C:\Users\Desktop\";
proc sort data=collegesummary(keep=college) out=unique nodupkey;by college ;run;
%macro repeat(dir=&dir,dsn=xxxxxxxx,group=xxxxxxxx);
ods rtf file="&dir.&dsn&sysdate..rtf" ;
proc report data=collegesummary nowd;
where college="&group";
column program report;
define program/display;
define report/display;
run;quit;
ods rtf close;
%mend repeat;
data _null_;
set unique;
call execute('%repeat(dir=,dsn='||strip(college)||',group='||strip(college)||')');
run;
Xia Keshan
Make a macro and repeat it by call execute .
proc sort data=collegesummary(keep=college) out=unique nodupkey;by college ;run;
%macro repeat(dir=xxxxxxx,dsn=xxxxxxxx,group=xxxxxxxx);
ods rtf path=&dir. file="&dsn&sysdate..rtf" ;
proc report data=collegesummary nowd;
where college="&group";
column program report;
define program/display;
define report/display;
run;quit;
ods rtf close;
%mend repeat;
data _null_;
set unique;
call execute('%repeat(dir=xxxxxxx,dsn='||strip(college)||',group='||strip(college)||')');
run;
Xia Keshan
Hello Keshan,
Thanks so much for your response. However, I got this error "ERROR: No logical assign for filename XXXXXXX." when I executed the code below:
---------------------------------------------------------------
Data collegesummary;
input college $ program $ report $;
cards;
LLL Chinese Yes
LLL English No
LLL Spanish Yes
LLL Korean No
Engineering Mechanical Yes
Engineering Chemical Yes
Engineering Electrical No
;
run;
title;
%let dir = "C:\Users\Desktop\";
proc sort data=collegesummary(keep=college) out=unique nodupkey;by college ;run;
%macro repeat(dir=xxxxxxx,dsn=xxxxxxxx,group=xxxxxxxx);
ods rtf path=&dir. file="&dsn&sysdate..rtf" ;
proc report data=collegesummary nowd;
where college="&group";
column program report;
define program/display;
define report/display;
run;quit;
ods rtf close;
%mend repeat;
data _null_;
set unique;
call execute('%repeat(dir=xxxxxxx,dsn='||strip(college)||',group='||strip(college)||')');
run;
--------------------------
This looks very promising. I'd appreciate any solution to this error.
Thanks,
Yao
Data collegesummary;
input college $ program $ report $;
cards;
LLL Chinese Yes
LLL English No
LLL Spanish Yes
LLL Korean No
Engineering Mechanical Yes
Engineering Chemical Yes
Engineering Electrical No
;
run;
title;
%let dir = "C:\Users\Desktop\";
proc sort data=collegesummary(keep=college) out=unique nodupkey;by college ;run;
%macro repeat(dir=&dir,dsn=xxxxxxxx,group=xxxxxxxx);
ods rtf file="&dir.&dsn&sysdate..rtf" ;
proc report data=collegesummary nowd;
where college="&group";
column program report;
define program/display;
define report/display;
run;quit;
ods rtf close;
%mend repeat;
data _null_;
set unique;
call execute('%repeat(dir=,dsn='||strip(college)||',group='||strip(college)||')');
run;
Xia Keshan
It worked. Thank you so much. This is going to be very helpful!
Yao
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.