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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.