The Monotonic Function
There is an undocumented function that enables you to generate observation numbers with a PROC SQL statement and retain them in an output data set.You can use the NUMBER option in a PROC SQL statement to print observation numbers, but the observation numbers are not retained (just like PROC PRINT w/o the nobs option).
To keep the observation numbers in the output table, use the MONOTONIC function in the SELECT statement.
Example:
Proc sql;
create table step1 as
select monotonic() as ID,
district, district_name
from perm.districts;
quit;
To do the same thing in a data step:
ID = _n_;

2 Comments:
The Monotonic Function is undocumented for SAS's version of SQL for a reason it can cause some unexpected results. This is documented by SAS.
So...what are the unexpected results? If you can elaborate please because I can't find anything on this @ SAS. This is the next best thing in proc sql if you do not want to do a data step.
Post a Comment
<< Home