BookmarkSubscribeRSS Feed
Niugg2010
Obsidian | Level 7

 

How can I prepare the below table with Proc report:

Thanks.

 

proc report

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

By writing SAS code yourself, or hiring a contractor to do the work for you.  You have not provided any test data (in the form of a datastep) nor have you shown anything you have tried so there is no "question" here to answer.  I don't see anything particularly complicated in what you have shown.

Niugg2010
Obsidian | Level 7

Proc report is based on column to prepare report. However, in my table some rows have two columns and some have foure columns. What 's why I am not sure how to prepare data.

I can use compute block to prepare the first row like:

 

compute before;

line @1 'aaaaaaaaaaaaaa';

endcomp;

 

but this is only one column, not like the first row.

 

In addition how to prepare row 4, 7, and 10;

 

compute after a=1; (here a=1 does not work)

line @1 'bbbbbbbbbbbbbb';

endcomp;

 

also;

 

compute after a;

if a=1 then line @1 'bbbbbbbbbbbbbb';   (If a=1 does not work)

endcomp.

 

 

Cynthia_sas
SAS Super FREQ
Also, when you post data, you also need to post ALL your code, including your ODS statements, not just a code snippet.
cynthia
Niugg2010
Obsidian | Level 7

Please find the code below:

 

data x;
format B $50. C D $10.;
A=1; B='aaaaaaaaaaa'; output;
A=1; B='aa'; C='aa';D='aa'; output;
A=1; B=' '; C=' ';D=' '; output;
A=2; B='bbbbbbbbbbbbbbbbbbb'; C=''; D=''; output;
A=2; B='bb'; C='bb';D='bb'; output;
A=2; B='bb'; C='bb';D='bb'; output;
A=3; B='cccccccccccccccccccc';C=''; D=''; output;
A=3; B='cc'; C='cc';D='cc'; output;
A=3; B='cc'; C='cc';D='cc'; output;
A=4; B='ddddddddddd'; C=''; D='';output;
A=4; B='dd'; C='dd';D='dd'; output;
A=4; B='dd'; C='dd';D='dd'; output;
run;
ods rtf file='C:\XXXX\Desktop\11111.rtf';
proc report data=x;
column A B C D;
define a /group;
run;
ods rtf close;

 

Below is output. Actually, I want rows of 1,4,7,10 across column B C D, not only in Column B.

Hopefully someone can help me out. Thanks.

 

1.jpg

Cynthia_sas
SAS Super FREQ

The way your data are currently structured makes it virtually impossible to have what you want -- you can't make the value you show (aaaaaaaaaa, bbbbbbbbb, etc) span columns B, C and D using PROC REPORT. However, you can have a LINE statement that spans ALL of the 4 columns. However, if your data were structured differently if might work. It would not look exactly as you want, but it would be closer than what you have now.

 

line_before.png
cynthia

 

Here's the alternate structure of the data, and a PROC FORMAT for the 4 main headers you want (I just numbered B, C and D so that I could be sure the rows were in the correct order and the data was read correctly:

data have;
  length b c d $10;
  infile datalines dlm=',';
  input a b $ c $ d $;
return;
datalines;
1,aa1,aa2,aa3
2,bb1,bb2,bb3
2,bb4,bb5,bb6
3,cc1,cc2,cc3
3,cc4,cc5,cc6
4,dd1,dd2,dd3
4,dd4,dd5,dd6
;
run;
 
proc format;
  value grpfmt 1 = 'aaaaaaaaaa'
               2 = 'bbbbbbbbbb'
	       3 = 'cccccccccc'
	       4 = 'dddddddddd';
run;
Cynthia_sas
SAS Super FREQ

Hi:

  Another way that you can do it (using the slightly different data that I posted) is to use the Report Writing Interface. It does the type of column-spanning you want. However, the RWI is not supported for RTF, but is supported for PDF. See below:

use_rwi_with_pdf.png

 

As you can see, it is possible to get what you want using the RWI, with a DATA step, not PROC REPORT. There will be a WARNING in the log if you use the code with RTF. Just remember that if you cannot use PDF for this, then your choice is to use PROC REPORT to get RTF and the first example I posted. Or to switch to PDF and get the above example.

 

Hope this helps,

cynthia

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
  • 8 replies
  • 1119 views
  • 1 like
  • 4 in conversation