What is _n_?
Answers were Sorted based on User's Feedback
Answer / sru
The value of _N_ represents the number of times the DATA
step has iterated
| Is This Answer Correct ? | 23 Yes | 2 No |
Answer / raghu
This is a data counter variable used in SAS.
..Raghu
| Is This Answer Correct ? | 14 Yes | 3 No |
Answer / ravi
This is nothing but a implict variable created by SAS during
data processing. It gives the total number of records SAS
has iterated in a dataset. It is Available only for data
step and not for procs.
Eg. If we want to find every third record in a Dataset then
we can use the _n_ as follows
Data new-sas-data-set;
Set old;
if mod(_n_,3)= 1 then;
run;
Note: If we use a where clause to subset the _n_ will not
yield the required result.
| Is This Answer Correct ? | 13 Yes | 3 No |
Answer / cutepa1
Almost all the above answers are right, except one or few.
Here I provide a clear insight into _n_ variable. This is an
automatic variable of PDV(Program Data Vector) that returns
the no. of observations that it has iterated. There are
such variables like _error_, end=, in=, first.by-variabke,
last.by-variable,etc.. All these variables will not be
displayed in the target output.
Ex:
data new;
set ora.emp;
if _n_ >= 2 and _n_ <= 6 then output;
run;
/* as _n_ returns 'n'th observation our statement is to save
those obs when _n_ returns the value between 2 and 6. Hence
the 5 obs of the specified dataset between second and six
are saved into 'new'.
| Is This Answer Correct ? | 7 Yes | 0 No |
Answer / hymad
this option is used to pick up n number of observation from
particular dataset
| Is This Answer Correct ? | 7 Yes | 3 No |
Answer / vijaibhaskar
_ n_ give no.of times data step is itereated .it gives
correct observations nos only if IF SUBSET IS NOT USED in
the datastep
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / madhavi
_n_ is a automatic variable created by SAS.we can use this
like we use any variable that we created ourselfs and it
indicates the number of times SAS has looped through the
data step.
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / arun
IT IS AUTOMATIC VARIABLE SHOWS NUMBER OF ITERATIONS.
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / suresh b anisetty
_n_ is a automatic variable the function of _n_ is how many
times the data step begins to execute.
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / yuva
its an automatic variable.it shows no. of iterations gone
through in datastep
| Is This Answer Correct ? | 3 Yes | 2 No |
Can you use a macro within another macro? If so how would SAS know where the current acro ended and the new one began?
for whom is sas data integration studio designed? : Sas-di
what can you learn from the sas log when debugging? : Sas programming
hi all, I need the SAS DI DUMP(A00 260) for attending the certification. if any one have, pls provide it.Please Email to vrpotluri@hotmail.com. Thanks - Ramana
How could you generate test data with no input data?
Do you use PROC REPORT or PROC TABULATE? Which do you prefer? Explain.
What are the applications primarily used by business analyst? : Sas-bi
What is SAS?
In which case u go for libname and in which case u go for proc sql pass thru facilit diff?
how to write code for left outer join in SAs using datastep?
What is your favorite all time computer book? Why?
If reading a variable length file with fixed input, how would you prevent SAS from reading the next record if the last variable didn’t have a value?