BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Carrotbing
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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

4 REPLIES 4
Ksharp
Super User

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

Carrotbing
Calcite | Level 5

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

Ksharp
Super User
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

Carrotbing
Calcite | Level 5

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

Yao

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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