+ All Categories
Home > Documents > Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans...

Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans...

Date post: 15-Jan-2016
Category:
Upload: bradyn-grass
View: 217 times
Download: 0 times
Share this document with a friend
33
Outline Proc Report Tricks Proc Report Tricks Kelley Weston Kelley Weston
Transcript
Page 1: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Proc Report TricksProc Report Tricks

Kelley WestonKelley Weston

Page 2: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Examples

1. Text that spans columns

2. Patient-level detail in the titles

3. Titles and footnotes at different places

4. Adding a space when adding a space doesn't work

5. Using a character that needs to sort before a space

6. Using a better underline

7. Stacking multiple variables in one column

8. Avoid orphaning groups of rows in listings

Ex 1 Ex 2 Ex 3 Ex 4 Ex 5 Ex 6 Ex 7 Ex 8

Page 3: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

1. Text that spans columns

Desired Output:

Patient Date 1 01NOV2005 Test 1: this is my sample long text

Test 2: this is my sample long text

2 02NOV2005 Test 1: this is my sample long text

Test 2: this is my sample long text

Page 4: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Notice that:

•Some information is in columns, under column headings (patient number and date)

•Some information is on multiple lines that spans columns (test 1 and test 2)

Page 5: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Sample code:

Create dataset:

data work.temp;input pt : $1. date : date9. @13 mytext $char50.;cards;1 01nov2005 this is my sample long text2 02nov2005 this is my sample long textrun;

Page 6: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Report code:

Part 1:

proc report data = work.temp nowd ; %* variable to be used in compute block must come before break variable; column mytext pt date;

define pt / order "Patient" width = 7 center ; define date / order "Date" width = 9 format = date9. left ;

Page 7: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Report Code

Part 2: *the variable to be used in the compute block must be defined as an order variable and use the noprint option; define mytext / order noprint; compute after pt; %* 1st method of printing line; line @3 "Test 1: " @12 mytext $50.; line " "; %* 2nd method of printing line; length text $75; text = "Test 2: " !! mytext; line @3 text $75.; line " "; endcomp; break after pt / skip; run;

Page 8: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

2. Patient-level detail in the titles

Desired Sample Output:____________Sample report <- title 1 linePatient: 1 Y = A <- title2 line _________ Z <- column heading _________ 9 <- variable value_____________Sample reportPatient: 2 Y = B____________

_________ Z _________ 8

Outline

Page 9: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Outline:

1. Put patient information in macro variables

2. Create proc report with titles containing macro variables

3. Wrap proc report within a macro loop to process all patients

Page 10: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Create dataset:

data work.temp; input patient y $ z; cards; 1 A 9 2 B 8run;

Page 11: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Step 1 - Put patient information into macro variables

proc sql noprint; select count(patient) into :cnt_x from work.temp;

%let cnt_x = &cnt_x;

select distinct patient, y into :x1 - :x&cnt_x /* patient number */ , :y1 - :y&cnt_x /* other var. to be in ttl */ from work.temp;quit;

Page 12: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Step 2 - Create proc report with titles containing macro variables

title1 "________________________________________"; title2 "Sample report"; title3 "Patient: &&x&cnt Y = &&y&cnt"; title4 "________________________________________"; proc report data = work.temp nowd headline; column ("__" z); define z / "Z"; where Patient = &&x&cnt; run;

Page 13: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Step 3 - Wrap proc report within a macro loop to process all patients

%macro test; %local cnt; %do cnt = 1 %to &cnt_x; title1 "________________________________________"; title2 "Sample report"; title3 "Patient: &&x&cnt Y = &&y&cnt"; title4 "________________________________________"; proc report data = work.temp nowd headline; column ("__" z); define z / "Z"; where Patient = &&x&cnt; run;

%end;%mend test;

%test;

Page 14: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

3. Titles and footnotes at different places

Outline

Page 15: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Titles within proc report:

proc report data = work.report column x; Define x / display;

compute before ; line "Title at the beginning of the report"; line " "; endcomp; %* between Titles & column headers; compute before _page_ / center; line "Title at the beginning of each page"; line " "; endcomp;

run;

Page 16: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Footnotes within proc report:

proc report data = work.report column x; Define x / display; %* before footnotes specified in Footnote stmts; compute after _page_ / center; line " "; line "Footnote at the end of each page"; endcomp;

compute after; line " "; line "Footnote at the end of the report"; endcomp;run;

Page 17: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

4. Adding a space when adding a space doesn't work

If Proc Report does not maintain the space you need (for example, in a label), then you can use ASCII 160 / hex A0) – used in column titles to indent (Proc Report won't keep space [ASCII 32])

Define x / " Column* Title" left;

Could still be printed as:ColumnTitle

When you really want:

bbColumnbbbbTitle

Page 18: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Two ways of achieving this:

If using UltraEdit, use the ASCII table:

View / ASCII table / click on Dec 160 / hex A0 / Click on Insert char

Page 19: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

If you are not using UltraEdit, then use the numeric keypad:

Alt – 0-1-6-0 (hold down the Alt key for the entire number.)

Page 20: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

5.5. Using a character that needs to sort before a spaceUsing a character that needs to sort before a space

If you have something in your report dataset that needs to sort before If you have something in your report dataset that needs to sort before something that contains a space, insert a null character (ASCII 00 / hex 00)something that contains a space, insert a null character (ASCII 00 / hex 00)

You can insert it into your data in the same way as inserting the "new" blank You can insert it into your data in the same way as inserting the "new" blank (ASCII 160).(ASCII 160).

For instance, when creating Adverse Event tables, and indenting the PT For instance, when creating Adverse Event tables, and indenting the PT (Preferred term) underneath the SOC (System Organ Class), and trying to (Preferred term) underneath the SOC (System Organ Class), and trying to get everything to sort properly, you can precede the SOC with an ASCII 00, get everything to sort properly, you can precede the SOC with an ASCII 00, which will sort before the space (ASCII 32 / hex 20)which will sort before the space (ASCII 32 / hex 20)

Page 21: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

6. Using a better underline (use "~~" in column statement, then use customized SAS macro)

Page 22: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Step 1: Run Proc Report to create *.lst file

Step 2: Run macro that will replace "~" with graphics character

Page 23: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Step 1: Run Proc Report:

proc report formchar(2) = "~"; /* by default this is a dash */ columns ("~~" vars1 - vars3 ); /* a dash is commonly used here */

Page 24: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Step 2: Run macro to replace "~" with graphics dash:

The macro contains the following code:

if index(text, '~') > 0 then text = tranwrd(text, '~', '97'x);

This replaces the tilde (~) with a graphics hyphen (—) in the list file. Normally, a regular hyphen (-) will be used, which will show space between the hyphens.

This assumes that the tilde will not be used anywhere else in the report.

Page 25: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

7. Stacking multiple variables in one column

The split character defined in the Proc Report statement will work not only in the label, but in the data as well:

col1 = trim(left(var1)) !! "#" !! trim(left(var2));

proc report split = "#" ;

Page 26: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

8.8. Avoid orphaning groups of rows in listingsAvoid orphaning groups of rows in listings

Adapted from "Controlling Page Breaks when using Proc Report", paper by Adapted from "Controlling Page Breaks when using Proc Report", paper by Cynthia Stetz, Merrill LynchCynthia Stetz, Merrill Lynch

There are times when you may want to keep all of group of items on a single There are times when you may want to keep all of group of items on a single page, instead of starting the group in the middle of one page, and continuing page, instead of starting the group in the middle of one page, and continuing the group on the next page. Instead of trying to account for it yourself, let the group on the next page. Instead of trying to account for it yourself, let SAS do it.SAS do it.

Page 27: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Step 1: Define number of observations in every group - used for page breaks in report

Step 2: Increment the page counter

Step 3: Proc Report Code

Page 28: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Step 1: Define # of obs in every group - used for page breaks in report

proc sql noprint; create table work.report as select *, count(visit) as rec_cnt from work.report group by site order by site, visit;quit;

Notes:• Site is the group-by, order-by, first. variable in this example. This is a variable that has the same value on many observations.• Visit is the variable that is being counted. It has a different value on every observation. It is not a group-by variable.

Page 29: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Sample Output

Obs site VISIT rec_cnt

1 00001 2 6 <- + 2 00001 4 6 | 6 obs 3 00001 6 6 | in 4 00001 7 6 | first 5 00001 8 6 | group 6 00001 9 6 <- + 7 00002 2 7 <- + 8 00002 4 7 | 7 obs 9 00002 6 7 | in 10 00002 7 7 | second 11 00002 8 7 | group 12 00002 9 7 | 13 00002 11 7 <- +

Page 30: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Step 2: Increment Page Counter

data work.report (drop = max lns_on_pg); set work.report; by site; retain lns_on_pg 0 max 48 /* less than page size value */ pg_ejct 1 /* break var. in proc report */; if first.site then do; %* +2 is to compensate for break lines; lns_on_pg = lns_on_pg + rec_cnt + 2; if lns_on_pg GT max then do; pg_ejct + 1; lns_on_pg = rec_cnt + 2; end; %* lns_on_pg GT max; end; %* first.site;run;

Page 31: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Sample Output:

After defining page eject (only 1st obs of each group shown)

Obs site VISIT rec_cnt pg_ejct

1 00001 2 6 1 <- + all obs ... | for these 7 00001 2 7 1 | sites 14 00003 2 8 1 | on 22 00004 2 8 1 | page one 30 00005 2 8 1 <- + 38 00006 2 6 2 page 2 starts

Page 32: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Step 3: Proc Report Code:

proc report; columns ("__" pg_ejct var1 -- var5);

define pg_ejct / order noprint;

break after pg_ejct / page; run;

Page 33: Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.

Outline

Thank you !

Kelley Weston

Quintiles


Recommended