BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hi Gurus,

Please help.

I would like to add a new ID column in existing table with the ID numbers equal the row numbers. Still don't know how.

ID
1
2
3
4
5
...


I know this is a dumb question, but.... Message was edited by: WAYNE66
1 ACCEPTED SOLUTION

Accepted Solutions
Bill
Quartz | Level 8
The data step carries a bunch of hidden variables in the pdv that disappear at the end of the data step. To keep them, one needs to insert them into another field. The one that you are interested in is _n_;

data new;
set old;
IDNew=_n_;
run;

View solution in original post

3 REPLIES 3
Bill
Quartz | Level 8
The data step carries a bunch of hidden variables in the pdv that disappear at the end of the data step. To keep them, one needs to insert them into another field. The one that you are interested in is _n_;

data new;
set old;
IDNew=_n_;
run;
deleted_user
Not applicable
Hi Wayne,
I have come up with a (sort of) solution, but for sure soon will get the exact solution to your query. Well this is what I thought of:
If you can create an ID variable in ur raw data set just analogous to your observation and in ur PROC PRINT use 'NOOBS' option... in dat case , ur ouput wud have soemthg like this:
ID
1
2
3
.
.
10
Now this is gonna be fine with few rows ,,, how if the raw data has 100s of rows(I mean really huge data????)???
Will find out and let u know sooner.Even I am eager to know abt this...

Regards,
SAS_Learner
tejeshwar
Calcite | Level 5
As Bill pointed out , a perfect way to do it is to use _n_. This keeps the row number at every row. Once you have a dataset, you just need to create a new variable which is = _n_ and this will work.

Thanks

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 44545 views
  • 2 likes
  • 3 in conversation