The SAS Output Delivery System and reporting techniques

How to generate separate files one for each by group using ods rtf

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

How to generate separate files one for each by group using ods rtf

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


Accepted Solutions
Solution
‎05-25-2014 03:01 AM
Super User
Posts: 9,681

Re: How to generate separate files one for each by group using ods rtf

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

View solution in original post


All Replies
Super User
Posts: 9,681

Re: How to generate separate files one for each by group using ods rtf

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

Occasional Contributor
Posts: 8

Re: How to generate separate files one for each by group using ods rtf

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

Solution
‎05-25-2014 03:01 AM
Super User
Posts: 9,681

Re: How to generate separate files one for each by group using ods rtf

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

Occasional Contributor
Posts: 8

Re: How to generate separate files one for each by group using ods rtf

It worked. Thank you so much. This is going to be very helpful!

Yao

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 541 views
  • 3 likes
  • 2 in conversation