The SAS Output Delivery System and reporting techniques

proc report issue

Reply
Frequent Contributor
Posts: 88

proc report issue

 

How can I prepare the below table with Proc report:

Thanks.

 

proc report

Super User
Super User
Posts: 7,720

Re: proc report issue

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.

Frequent Contributor
Posts: 88

Re: proc report issue

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.

 

 

Super User
Posts: 7,444

Re: proc report issue

I still can't see any example date here. Programs without data are useless. See my previous post how to post the example data.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
SAS Super FREQ
Posts: 8,820

Re: proc report issue

Also, when you post data, you also need to post ALL your code, including your ODS statements, not just a code snippet.
cynthia
Super User
Posts: 7,444

Re: proc report issue

[ Edited ]

How to provide test/example data in a data step:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 88

Re: proc report issue

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

SAS Super FREQ
Posts: 8,820

Re: proc report issue

[ Edited ]

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;
SAS Super FREQ
Posts: 8,820

Re: proc report issue

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

Ask a Question
Discussion stats
  • 8 replies
  • 204 views
  • 1 like
  • 4 in conversation