|
_N_ automatically appears in every data step. This variable counts the number of times the observartion loop has begun executing in a step. _N_ always has the value 1 at the start of a data step, and its value increments by 1 whenever a RETURN statement is executed (including the implicit RETURN statement at the end of the data step, with the exemption of when returning after a LINK statement or HEADER= transfer is executed). _N_ also increases by 1 when a DELETE statement is executed or when a nesting IF is executed with a false condition. However, the value of _N_ will not add up by the LOSTCARD statement.
In this example, I use _N_ to assign a unique number where my result should be preceeding with zeros. Using the put function with the _N_ variable and the z7. format to generate the desired result.
|
data test;
set carlo.questlab;
COUNTER="&sysdate" | | put(_n_, z7. -L);
run;
proc print data=workdata;
run;
The SAS System
Obs CIN COUNTER
1 TR69717V 22FEB050000001
2 VN91521M 22FEB050000002
3 XZ51736Z 22FEB050000003
4 WM18414E 22FEB050000004
5 XF47182B 22FEB050000005
6 XV64986B 22FEB050000006
7 XE61748H 22FEB050000007
8 TF15128K 22FEB050000008
9 TG56707T 22FEB050000009
|
|