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
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?
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.