BookmarkSubscribeRSS Feed
dandip
Fluorite | Level 6
I've searched high and low and can't find an answer to this problem, and had just responded to Rick Wicklin's last post on PROC DOCUMENT. An example will illustrate the problem I'm having. Suppose a clinical trial with 5 subjects (DM), and only 1 of whom has an AE (subject 3). data demog; input usubjid @@; age = 70; cards; 1 2 3 4 5 run; data ae; input usubjid evt $ @@; cards; 3 AE1 3 AE2 3 AE3 ; run; What I'd like to end up with, via ODS PDF, is to generate the TOC after I run PROC PRINT or PROC REPORT for each subject (grf1.jpg). Now I can easily achieve this using ODS and PROC DOCUMENT if I process each subject in a loop, by naming the objects and directing them to folders and so forth. What I am unable to do is to repeat if, instead of a macro going subject by subject, I try to use a BY statement, which would be much more efficient than a looping a macro. The problem that I face, and can't solve, is that subject 3, in AE, is the first patient to have AEs, so this gets assigned ByGroup1#1 (see grf2.jpg). No matter how I try to move things around, it seems I can't get the 1:1 match between AEs and DM that I want, using the by groups. One can imagine the challenges when we have different domains not having a 1:1 match for subjects (CM (conmeds) CE (events), etc.). Thanks - if you'd like to see how I handled this with macros and looping, I can share it. Dan.
grf2.jpggrf1.jpg
4 REPLIES 4
ballardw
Super User

Perhaps you need a step to determine a new grouping variable (or variables), add that to the data and use that new variable for By group processing?

dandip
Fluorite | Level 6

Thanks Grand Advisor.   I thought of it, and in fact, made sense to say something like "No AEs for this Subject" and create the dummy record.  But it seemed to be more tedious and cumbersome than I wanted, and with Cynthia's reference and a correspondence with Rick Wicklin from SAS and his thread, it got me where I needed to be.  So I arrived at the solution.

 

Thanks

Dan

Cynthia_sas
SAS Super FREQ
Hi: The issue with BY group processing is that every BY group is a unit and so the procedure or program that does the BY groups for AE will have to finish ALL the AE's before it starts the BY groups for all the DM. In this paper, https://support.sas.com/resources/papers/sgf09/318-2009.pdf I show how a sort of related scenario in which all the by groups in a PROC TABULATE step occur before all the BY groups in a UNIVARIATE step. (see default output on page 2).

But then, the desired output is shown on page 11 in Figure 21.

Of course, my BY groups did have a 1-to-1 correspondence, which made the PROC DOCUMENT program, starting on page 12 easier.

The advantage of Macro processing is that it allows you to make a "package" of the needed AE and DM code and then run the package 1 time for every subject and if there's an AE for that subject, then the AE will get output with the right DM. And, macro gives you more control over the names.

cynthia
dandip
Fluorite | Level 6

Thanks Cynthia.  That was a big help, although not the ultimate solution.  But I did take that, and took advantage of ods output properties from PROC DOCUMENT to associate the path with the subject.   Moved things around, and here's a working prototype.

 

Of course, this will need be generalized to replace "Print" with the actual proc, etc, but it's a great start.  And it got what I wanted - so thanks again:

 

data demog;
input usubjid @@;
age = 70;
cards;
1 2 3 4 5
;
run;

data ae;
input usubjid evt $ @@;
cards;
3 AE1 3 AE2 3 AE3
;
run;

data cm;
input usubjid evt $ @@;
cards;
2 CM1 2 CM2 2 CM3
;
run;

 


ods document name=work.forsuperfreq(write);

proc print data=demog;
by usubjid;
run;

proc print data=ae;
by usubjid;
run;

proc print data=cm;
by usubjid;
run;

ods document close;

ods trace off;

ods output properties=props;
proc document name=work.forsuperfreq(update);
list / levels=all bygroups; /* add column for each BY group var */
run;
quit;

proc sql noprint;
select distinct path, cats("\Subject",usubjid)
into :from1-:from7, :to1-:to7
from props;
quit;

%put &from1 &from2 &to1 &to2;

options symbolgen mprint mlogic;

proc document name=work.forsuperfreq(update);
dir ^^;
%macro createsubdirs;
%do j=1 %to 5;
make \Subject&j;
run;
%end;
%mend;
%createsubdirs;
list /levels=all;
run;

dir ^^;

%macro movefolders;
%do k=1 %to 7;
move &&from&k to ^&&to&k.\Print ;
run;
%end;
%mend;

%movefolders;
list /levels=all;


ods pdf file = 'm:\procdocumentsandbox\filehelp.pdf';
dir ^^;
replay /;
run;
ods pdf close;
run;

quit;

 

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
  • 1043 views
  • 0 likes
  • 3 in conversation