Please try below code
data have;
input loan_num $ date1 date9.;
format date1 date9.; datalines;
111 11jun2019
111 11jul2019
112 11aug2019
113 11sep2019
113 11oct2019
114 11oct2019
;
run;
proc sort data=have;
by loan_num date1;
run;
data want;
set have;
by loan_num date1;
if first.loan_num then Row_Num=1;
else Row_Num=0;
run;
Please try below code
data have;
input loan_num $ date1 date9.;
format date1 date9.; datalines;
111 11jun2019
111 11jul2019
112 11aug2019
113 11sep2019
113 11oct2019
114 11oct2019
;
run;
proc sort data=have;
by loan_num date1;
run;
data want;
set have;
by loan_num date1;
if first.loan_num then Row_Num=1;
else Row_Num=0;
run;
PLEASE do not (and I mean NOT) post code into the main posting window, or c**p like this happens:
@Q1983 wrote:
data have; input loan_num $ date1 date9.; format date1 date9.; datalines; 111 11jun2019 111 11jul2019 112 11aug2019 113 11sep2019 113 11oct2019 114 11oct2019 ;run; Produces 111 11jun2019 111 11jul2019 112 11aug2019 113 11sep2019 113 11oct2019 114 11oct2019 I need to assign a row number to each distinct Loan_num such as loan_num date1 Row_Num 111 11Jun2019 1 111 11Jul2019 0 112 11Aug2019 1 113 11Sep2019 1 113 11Oct2019 0 114 11Oct2019 1 If the loan_num only appears once, assign a 1. If the loan_num appears twice, assign a 1 to the first one and a 0 to any subsequent loan_num
Use the "little running man" instead, it's next to the </> marked here:
It's not rocket science, and it won't make your head explode. Promised.
To your question:
sort the data by loan_num and whatever you want as an additional sort order, and then, in a subsequent data step, do
by loan_num;
newvar = first.loan_num;
That's all.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.