The SAS Output Delivery System and reporting techniques

Copy PROC REPORT result into a dataset.

Reply
Occasional Contributor
Posts: 7

Copy PROC REPORT result into a dataset.

Hi,

I create a report using the PROC REPORT facility, and this is how my code looks :-

PROC REPORT DATA=MERGED NOCENTER NOWD HEADLINE HEADSKIP MISSING;
COLUMN SDC SDCDESC N SHEETCT;
DEFINE SDC / GROUP FORMAT=£4. 'SDC';
DEFINE SDCDESC / GROUP FORMAT=£40. 'PRODUCT DESCRIPTION';
DEFINE SHEETCT / ANALYSIS SUM FORMAT=7. 'SHEET COUNT';

COMPUTE AFTER;
LINE "TOTAL MPKT COUNT : "
N 10.;
LINE "TOTAL SHEET COUNT: "
SHEETCT.SUM 10.;
ENDCOMP;

I execute this in the mainframe, using a batch job written in JCL. And when I complete running this job, I am able to see the report in SASLIST (similar to sysout). Now I want the o/p of PROC REPORT to be moved into a dataset.

Can someone please let me know how I can do that !

Thanks.
SAS Super FREQ
Posts: 8,742

Re: Copy PROC REPORT result into a dataset.

Hi:
PROC REPORT supports an OUT= option like this:
[pre]
PROC REPORT DATA=MERGED NOCENTER NOWD
HEADLINE HEADSKIP MISSING OUT=work.reptout;

PROC REPORT DATA=MERGED NOCENTER NOWD
HEADLINE HEADSKIP MISSING OUT=permlib.reptout;

[/pre]

Of course, options like HEADLINE/HEADSKIP have no effect the output dataset. In addition, output from LINE statements is not put into the dataset. You will also notice an extra variable is added to the output dataset. This variable is named _BREAK_ and if you have BREAK or RBREAK statements in your code, you will see output that looks like this:
[pre]
Obs Region Product Sales _BREAK_

1 Asia Boot $62,708
2 Asia Men's Casual $11,754
3 Asia Men's Dress $119,366
4 Asia Sandal $8,208
5 Asia Slipper $152,032
6 Asia Sport Shoe $2,092
7 Asia Women's Casual $25,837
8 Asia Women's Dress $78,234
9 Asia Total $460,231 Region
10 Canada Boot $385,613
11 Canada Men's Casual $441,903
12 Canada Men's Dress $920,101
13 Canada Sandal $14,798
14 Canada Slipper $952,751
15 Canada Sport Shoe $140,389
16 Canada Women's Casual $410,807
17 Canada Women's Dress $989,350
18 Canada Total $4,255,712 Region
19 Total $4,715,943 _RBREAK_


[/pre]

This output was created with the program shown below.
You cannot currently use the OUT= option with a PROC REPORT that uses a BY statement.

cynthia

[pre]
ods listing;
proc report data=sashelp.shoes nowd
out=work.reptout;
where region in ('Asia', 'Canada');
column region product sales;
define region / group;
define product /group;
define sales /sum;
break after region /summarize skip;
compute after region;
region = trim(region)||' Total';
endcomp;
rbreak after / summarize;
compute after;
region = 'Total';
endcomp;
run;

options nocenter nodate nonumber;
proc print data=work.reptout;
run;
[/pre]
Occasional Contributor
Posts: 7

Re: Copy PROC REPORT result into a dataset.

Thanks a lot Cynthia ! I also found that there is a command called PRINTTO, which routes the SAS PROC output to a dataset !

This is how I coded it :-

PROC PRINTTO PRINT=SASOUT NEW;
RUN;

Many Thanks,
Murali.
N/A
Posts: 0

Re: Copy PROC REPORT result into a dataset.

Actually, PrintTo doesn't write to a data set, it writes textual content to a file.

"DATASET" implies a SAS construction of defined columns and populated rows, and this is what Cynthia's answer will give you.

Kind regards

David
Ask a Question
Discussion stats
  • 3 replies
  • 131 views
  • 0 likes
  • 3 in conversation