Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SAS - Table Row Number

Status
Not open for further replies.

Romary

IS-IT--Management
Mar 12, 2003
9
US
I have a table and I want a field to be the row number. How would I do this?
 
Hi,

The answer is very simple. Use this data step below

Data new;
set old;
n=_n_;
run;

Now the new data set will contain a varible(n) which holds the number of the row.

Feel free to ask further questions.

Thanks
 
I wouldn't use that method as that doesn't take into account the records marked for deletion.
I have seen cases that the _n_ value is incorrect. You could use the increment operator to get the same results.


data Test;
set old;
i=1;
run;

Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top