LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 1996, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 8 Apr 1996 19:11:05 GMT
Reply-To:     Sean Sullivan <sps_ba@IX.NETCOM.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Sean Sullivan <sps_ba@IX.NETCOM.COM>
Organization: Netcom
Subject:      Re: more about OBS and _N_

Chun Huang <CHUN@MANA.MEDSURF.COM> wrote:

Simply put, _N_ counts the number of interations of the datastep, not the number of observations in the data.

>Dear SAS-Lers: > >Yesterday Sudhakar asked how to get the sequence number of observation >in a sas data set and use it in the analysis. In my response to the >message, I suggested that a sum statement (e.g., OBS_NUM+1) can be >used in this situation. In response to Sudhakar's message, Whittington >et al. suggest using the automatic variable, _N_. Several people also >sent messages to me and kindly reminded me that using _N_ is the best >way to do this. However, I think it may or may not be the best way. >Joe has pointed out the potential problems with _N_. Here I >would like to provide another very simple example: > >DATA TEST; >INPUT ID X; >IF ID=2 THEN DELETE; >IF ID NE 3; >NUM_OBS+1; >N=_N_; >CARDS; >1 11 >2 12 >3 13 >4 14 >5 15 >; >RUN; >PROC PRINT; >RUN; > >The SAS System 1 >08:58 Thursday, April 4, 1996 > >OBS ID X NUM_OBS N > >1 1 11 1 1 >2 4 14 2 4 >3 5 15 3 5 > >This example shows that the value of _N_ also increases by 1 when a >IF---THEN DELETE statement is executed or when a subsetting IF is >executed with a false condition; but the sum statement does not (as >long as it used after the IF statements). _N_ may give us >unexpected and misleading value in this situation. > >Chun Huang, Ph.D > > >Chun Huang, Ph.D. >Hawaii Osteoporosis Center >Email: chuang@mana.medsurf.com

*************************************** Sean P. Sullivan MICS Administrator Key Services Corporation NY-31-22-0303 22 Corp Woods Blvd Albany, NY 12211 USA 1-518-391-6009 s_sullivan@keycorp.e-mail.com sps_ba@ix.netcom.com ******************************************


Back to: Top of message | Previous page | Main SAS-L page