The SAS Output Delivery System and reporting techniques

Is _N_ available for PROC REPORT

Reply
Frequent Contributor
Posts: 97

Is _N_ available for PROC REPORT

Hello,

I want to print the report for a range of records i.e. for observation 10 to 20 and then 40 to 50, without modifying the source dataset to add _N_ as a column.

Is _N_ available to PROC REPORT?

Can you please suggest some other option without having the need to modify the source dataset.

Regards
Sanjay
SAS Super FREQ
Posts: 8,868

Re: Is _N_ available for PROC REPORT

Hi:
_N_ is only available as an automatic variable in a DATA step program. PROC PRINT has another (different) method for showing OBS number in it's output.

The OBS= and FIRSTOBS= options allow you to select observations, however, you will need 1 step for OBS=10-20 and another step for obs 40-50, as shown in the program below. SASHELP.SHOES has 358 observations... I created an ORIGOBS column just to prove that FIRSTOBS and OBS worked.

Do remember that if your input dataset somehow gets sorted that different observations might be selected in subsequent runs of your PROC REPORT code. Also, after using OBS= and FIRSTOBS= options, you will want to set the limit back to OBS=MAX and FIRSTOBS=1 so that subsequent procedures are not impacted by these options.

cynthia
[pre]
options obs=max firstobs=1;
data shoes;
set sashelp.shoes;
origobs = _n_;
run;

ods html file='c:\temp\useobs_firstobs.html' style=sasweb;
options obs=10 firstobs=1;
proc report data=shoes nowd;
title 'firstobs=1 obs=10';
run;

options obs=50 firstobs=40;
proc report data=shoes nowd;
title 'firstobs=40 obs=50';
run;
ods html close;

options obs=max firstobs=1;
[/pre] ** use this code to reset BOTH options:
[pre]
options obs=max firstobs=1;
[/pre]


Message was edited by: Cynthia@sas
Frequent Contributor
Posts: 97

Re: Is _N_ available for PROC REPORT

Posted in reply to Cynthia_sas
Thanks Cynthia.

That's fantastic.
Ask a Question
Discussion stats
  • 2 replies
  • 642 views
  • 0 likes
  • 2 in conversation