BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ranjit1
Calcite | Level 5

I want the SRNO variable in following manner

CIF ACNO SRNO
123 14 1
123 15 2
123 16 3
159 17 1
159 18 2
159 19 3
159 20 4
159 30 5

but after running the code:

data DATA3;
set data1 ;
by cif  ;
srno + 1;
if first.cif then srno=1;

run;

I get the result:

CIF ACNO SRNO
123 14 1
123 15 2
123 16 2
159 17 1
159 18 2
159 19 2
159 20 2
159 30 2

 

Thanks in advance for your guidance. 

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Can't be.

data data1;
input cif acno;
datalines;
123 14
123 15
123 16
159 17
159 18
159 19
159 20
159 30
;
run;

data data3;
set data1;
by cif;
srno + 1;
if first.cif then srno = 1;
run;

proc print data=data3 noobs;
run;

Result:

cif    acno    srno

123     14       1 
123     15       2 
123     16       3 
159     17       1 
159     18       2 
159     19       3 
159     20       4 
159     30       5 

Could it be that variable SRNO is already in your dataset, with a constant value of 1?

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data have;
input CIF ACNO;
datalines;
123 14
123 15
123 16
159 17
159 18
159 19
159 20
159 30
;

data want;
   set have;
   by CIF;
   if first.CIF then srno=1;
   else srno+1;
run;
Kurt_Bremser
Super User

Can't be.

data data1;
input cif acno;
datalines;
123 14
123 15
123 16
159 17
159 18
159 19
159 20
159 30
;
run;

data data3;
set data1;
by cif;
srno + 1;
if first.cif then srno = 1;
run;

proc print data=data3 noobs;
run;

Result:

cif    acno    srno

123     14       1 
123     15       2 
123     16       3 
159     17       1 
159     18       2 
159     19       3 
159     20       4 
159     30       5 

Could it be that variable SRNO is already in your dataset, with a constant value of 1?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 10040 views
  • 1 like
  • 3 in conversation