I have a vehicle count variable that I need to assign a vehicle number from. I think I need an enumeration of some type...the last column is the column I need to create.
VC VN 1 1 1 1 1 1 1 1 1 1
2 1
2 2
2 1
2 2
2 1
3 1
3 2
3 3
3 1
Based on your sample data something like below could work.
data have;
input vc vn;
datalines;
1 1
1 1
1 1
1 1
1 1
2 1
2 2
2 1
2 2
2 1
3 1
3 2
3 3
3 1
;
data want(drop=_:);
set have;
by vc;
if first.vc then
do;
_s2+1;
_s1=_s2;
end;
else _s1+1;
vn_calc=1+mod(_s1,_s2);
run;
proc print data=want;
run;
Is this a Rorschach test ?
I cannot see a pattern there.
So you you will need to describe the rule if you us to help you with code to implement it.
I have never considered Enumeration of a variable. What does that mean?
I know how to number OBSERVATIONS.
data want;
set have;
obs_number + 1;
run;
I know how to number GROUPS.
data want;
set have;
by group_name;
group_number + first.group_name;
run;
I know how to number the members of a group.
data want;
set have;
by group_name;
member_number + 1;
if first.group_name then member_number=1;
run;
Based on your sample data something like below could work.
data have;
input vc vn;
datalines;
1 1
1 1
1 1
1 1
1 1
2 1
2 2
2 1
2 2
2 1
3 1
3 2
3 3
3 1
;
data want(drop=_:);
set have;
by vc;
if first.vc then
do;
_s2+1;
_s1=_s2;
end;
else _s1+1;
vn_calc=1+mod(_s1,_s2);
run;
proc print data=want;
run;
Amazing, thank you so much!
data want;
set have;
by vc;
retain counter;
if first.vc then counter=0;
counter = ifn(counter<VC, counter+1, 1);
/*if counter<VC then counter+1; else counter=1;*/
run;
@chsprogramming wrote:
I have a vehicle count variable that I need to assign a vehicle number from. I think I need an enumeration of some type...the last column is the column I need to create.
VC VN 1 1 1 1 1 1 1 1 1 1
2 1
2 2
2 1
2 2
2 1
3 1
3 2
3 3
3 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!
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.
Ready to level-up your skills? Choose your own adventure.