🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-06-2019 09:31 AM
(10383 views)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?