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

In short: I am using proc report, and I want to make a report that has a line break to before the first row associated with a group, but only for certain variables. 

 

I am trying to format a table to look like the Dream Table image shown below. I am making a demographics table similar to what's demonstrated in the invaluable paper Tips and Tricks for Making the Reports Your Clients Need to See.

The difference between what that paper does and what I want to do is that I want to treat the continuous variables differently than the categorical variables. I want the categorical variables to be exactly the same as that paper shows, with the variable name displayed in a line above the categories/results. However, in a departure from the paper, I want one line per continuous variable (no break with the variable name above). This means that I need a line break to be before the first row associated with a group (in this case the variable), but only for certain variables.

Dream TableDream Table

 

I can conditionally insert a line break for the categorical variables, but I can only insert it above every line in the group, and I want it once before the group begins. Example of what I'm currently getting is shown below.

 

Reality TableReality Table

 

I'm including my fake data set as a CSV file because it's extremely tortured. My code is below. Please ignore the style differences in the output, I used a custom style to make the above table and it seemed too long/irrelevant to include in this post.

 

options missing = " ";
ODS RTF style = journal FILE= "&outpathway.\NewLayout &SYSDATE..DOC"; 

proc report nowindows data=NewTest split="~" 
	style=[frame = hsides rules=groups]
	style(header lines)=[font_face="calibri"]
	style(column)=[font_face="calibri" just=center]
;
	 column Variable_Order Variable_Name Level_Order type ("Variable" New_Category) Grouper,Result ("P-Value" pvalue) ;
	 define Variable_Order / group noprint order=internal ;
	 define Variable_Name / group noprint order=internal ;

	 define Level_Order / group noprint order=internal ;
	 define type / group  noprint;
	 define New_Category / group ' ' style=[just=left protectspecialchars=off];
	 define Grouper / across "Group \brdrb\brdrs" format = $50.
	 	style=[protectspecialchars=off]
	 	order = internal  ; 
	 define Result / group ' ' format=$50. ;
	 define pvalue /  max  " " format=pvalue6.3 ; 
		         COMPUTE pvalue; 
		              IF . < _c8_ <0.05 THEN 
		               CALL DEFINE("_c8_", "STYLE", "STYLE=[FONT_WEIGHT=BOLD]");
		         ENDCOMP;

	 compute before type ;
		if type = "C" then do;
				num = 50;
				text = Variable_Name;
			end;
		else do;
			num = 0;
			text = "";
		end;

		
	 	line @1 text $varying. num ; 

	 endcomp;

 run; 
 ODS RTF CLOSE; 

Many thanks in advance!

 

PS I'm using SAS 9.4 (TS1M2).

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  I changed your data a bit to get rid of some of the RTF control strings for indenting and used ODS STYLE overrides for that:


data newtest;
  length Grouper $8 Variable_Name $20 Level $20 type $1 Result $30 New_Category $20;
  infile datalines dlm=',' dsd;
  input Grouper $ Variable_Name $ Variable_Order Level $ Level_Order Result $ 
        New_Category $ Type $ pvalue;
  datalines;
Group 1,Age,1,,1,"15 (13, 17)",Age,N,0.683
Group 2,Age,1,,1,"16 (13, 17)",Age,N,.
Group 1,Weight,2,,1,"54.95 (41.6, 66.9)",Weight,N,0.326
Group 2,Weight,2,,1,"51.2 (37.7, 62)",Weight,N,.
Group 1,Discharge Opioid,3,N,1,38 (69.09%),N,C,0.06
Group 2,Discharge Opioid,3,N,1,13 (30.23%),N,C,.
Group 1,Discharge Opioid,3,Y,2,17 (30.91%),Y,C,.
Group 2,Discharge Opioid,3,Y,2,30 (69.77%),Y,C,.
;
run;

Then I was able to get this:

demographic_indent.png

 

By changing your logic and moving TYPE to a different location on the COLUMN statement -- I was able to get the Discharge Opioid header to only appear one time. The issue with your original output was that TYPE was too far down in the COLUMN statement so your original COMPUTE BEFORE TYPE was causing the string to be written before each row for TYPE. This arrangement and logic worked better for me.

code_for_demog.png

 

I can get the line at the top of the table (before the first header) or the bottom of the table (after the last row) thicker, but I cannot get the line under the column headers to be thicker, so I left that part undone. You may have to ask Tech Support for help with that. I kept the RTF control strings for the underline for Group because the ODS style override would only underline the word, not the entire cell, but RTF controls will underline the cell. I used ODS style overrides for indenting. I made the N and Y bold, but you don't have to do that.

 

Hope this helps,

Cynthia

View solution in original post

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi:

  I changed your data a bit to get rid of some of the RTF control strings for indenting and used ODS STYLE overrides for that:


data newtest;
  length Grouper $8 Variable_Name $20 Level $20 type $1 Result $30 New_Category $20;
  infile datalines dlm=',' dsd;
  input Grouper $ Variable_Name $ Variable_Order Level $ Level_Order Result $ 
        New_Category $ Type $ pvalue;
  datalines;
Group 1,Age,1,,1,"15 (13, 17)",Age,N,0.683
Group 2,Age,1,,1,"16 (13, 17)",Age,N,.
Group 1,Weight,2,,1,"54.95 (41.6, 66.9)",Weight,N,0.326
Group 2,Weight,2,,1,"51.2 (37.7, 62)",Weight,N,.
Group 1,Discharge Opioid,3,N,1,38 (69.09%),N,C,0.06
Group 2,Discharge Opioid,3,N,1,13 (30.23%),N,C,.
Group 1,Discharge Opioid,3,Y,2,17 (30.91%),Y,C,.
Group 2,Discharge Opioid,3,Y,2,30 (69.77%),Y,C,.
;
run;

Then I was able to get this:

demographic_indent.png

 

By changing your logic and moving TYPE to a different location on the COLUMN statement -- I was able to get the Discharge Opioid header to only appear one time. The issue with your original output was that TYPE was too far down in the COLUMN statement so your original COMPUTE BEFORE TYPE was causing the string to be written before each row for TYPE. This arrangement and logic worked better for me.

code_for_demog.png

 

I can get the line at the top of the table (before the first header) or the bottom of the table (after the last row) thicker, but I cannot get the line under the column headers to be thicker, so I left that part undone. You may have to ask Tech Support for help with that. I kept the RTF control strings for the underline for Group because the ODS style override would only underline the word, not the entire cell, but RTF controls will underline the cell. I used ODS style overrides for indenting. I made the N and Y bold, but you don't have to do that.

 

Hope this helps,

Cynthia

Martha
Fluorite | Level 6

Thank you so much! Moving the type variable is exactly the key.

 

No worries about the style used with the thicker line placement - I have a style template I'm using that implements all of that. I just couldn't work out the line breaks properly.

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 674 views
  • 0 likes
  • 2 in conversation