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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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