BookmarkSubscribeRSS Feed
Zhenek
Calcite | Level 5

Hello, colleagues.

 

I'm responsible for randomization, and, in particular, coding. The task I have to complete is to create 2 huge word documents with each page in them serving as a label to be printed later on with the intention to glue it on a cover of an envelope or to be used as the contents of an envelope. This particular study uses envelopes for randomization.

 

The first document should be like this: each page should have text in the middle with name of the study and whatnot and then the next line would be just the "Envelope number: x

 

The second document is a bit diffferent: 3 lines in the middle, first line is just the study name, second line is randomization number and third line is the kit number.

 

In my disposal I got a data set X with 2 columns (randnum, kitnum) and 150 rows. First column is randomization number and second column is the kit number.

 

The idea I had in mind was to use the %do-loop inside a macro after an "ods rtf file" statement, which would, using a data step, fetch a row of the data set X and then using ods rtf text statement with the startpage = now I'd be able to create the desired document:

 

The code would look like this:

 

 

%macro M;

local i;

 %do i = 1 %to 150;


data temp;

      set x;

      where _N_ = &i;

      call symput('randnum',randnum);

      call symput('kitnum',kitnum);

run;

ods rtf text "to-be-redacted-when-code-works: &randnum, &kitnum); 
/* many other lines to make the pages look approproate */
%end; %mend M; options nodate nonumber byline; ods escapechar = "^"; ods listing close; ods rtf file = "<my_destination_folder>" startpage=no; %M; ods _all_ close; ods listing;

 

 But sadly the result fails and the myriad of errors tell me that I either do not understand the %do-loop statement or ods rtf statements simply do not work for this purpose.

 

Could anyone help out to point at the errors or suggest a viable alternative?

 

Thanks in advance.

3 REPLIES 3
andreas_lds
Jade | Level 19
Start without macro stuff and get the thing set and running for one document. Then think about macro statements.

Using call execute to generate the statements in a loop seems to be more efficient in this case, but I am 100% sure that I don't understand half of what you plan to do.
ballardw
Super User

I am not sure I am understanding your use of "document".

Are you attempting to create one rtf file with information per page that you will PRINT?

 

Does this come at all close to what the first requirement may be? I have provided a short dummy data set to process, change the path on the ODS RTF statement to match your need.

data junk;
   input x kit;
   label x="Envelope Number";
datalines ;
4      423
257    275
83     888
18     897
;
run;

ods rtf file='c:\path\first.rtf'
   bodytitle notoc_data
;
ods noproctitle;
options nobyline;
proc print data=junk noobs label;
   title "This is invariate text that would repeat for each page";
   title2 "use more title lines if more lines are needed";
   by notsorted x;
   var x;
run;
ods rtf close;
Zhenek
Calcite | Level 5

Hello, colleagues.

 

I'm very sorry for the long absence but I guess I ought to give this case a closure.

 

This is the solution that worked for me.

 

data junk;
   input randnum kit_number;
datalines ;
4      423
257    275
83     888
18     897
;
run;

%macro M;

local i;

 %do i = 1 %to 4;

 data temp;

      set junk;

      if _N_ = &i;

      call symput('randnum',randnum);

      call symput('kitnum',kit_number);

run;

data temp2;
   text = " ^n^n^n^n^n^n^n^n^n^n^n^n^n^n^n
            Investigation number №:  ^S={font_weight=bold} XXXXXXXXXXX ^n^n
               ^S={font_weight=light}Randomization number: &randnum ^n^n
             Kit number: &kitnum";

run;

proc report data=temp2 nowd noheader style(report)={rules=none frame=void}
     style(column)={font_size=14pt just=l};
run;

ods startpage = now;

%end;

%mend M;

options nodate nonumber byline orientation=portrait papersize=letter;
ods escapechar = "^";
ods listing close;
ods rtf file = "C:\Users\Username\contents.rtf" startpage=yes;
%M;
ods _all_ close;
ods listing;

 

The result is 4 pages in rtf file with similar content in the middle of each page. This will be used as contents for envelopes in the blinded randomization trial with appropriate data (150 pages)

 

Thanks everyone for your input!

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 654 views
  • 2 likes
  • 3 in conversation