BookmarkSubscribeRSS Feed
SanjayM
Calcite | Level 5
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
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
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
SanjayM
Calcite | Level 5
Thanks Cynthia.

That's fantastic.

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