BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

I have this table

A      B    

10     0.1  

10    0.1    

22     0.1   

22    0.2    

22    0.2    

31     0.2    

31     0.3    

I want to add ID

A      B     ID

10     0.1    1

10    0.1     1

22     0.1    2

22    0.2     2

22    0.2     2

31     0.2     3

31     0.3     3

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

data want;

set have;

by a;

if first.a then id+1;

run;

View solution in original post

5 REPLIES 5
stat_sas
Ammonite | Level 13

data want;

set have;

by a;

if first.a then id+1;

run;

sasphd
Lapis Lazuli | Level 10

I can not do that because A is not properly sorted???????????????

stat_sas
Ammonite | Level 13

What is the criteria to create id then?

sasphd
Lapis Lazuli | Level 10

the criteria is that A must be the same for the id=1.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Then sort the data.  If you need original sorting then do:

data have;

     set a;

     prev_sort=_n_;

run;

proc sort data=have;

     by a b;

run;

data want;

set have;

by a;

if first.a then id+1;

run;

proc sort data=want;

     by prev_sort;

run;

However, if your test data is right (and after this sort statement I am not sure), just say:

data want;

     set have;

     do I=1 to 100;

          if (i *10) < a <= ((I+1) * 10) then id=I;

     end;

run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 1397 views
  • 3 likes
  • 3 in conversation