Hi,
I need to populate a count_var variable in my dataset based on the value of Order Id, Dataset format is as follows:
Order ID Count_var
000123 1
000123 2
000123 3
000125 1
000125 2
000130 1
Here Count_var variable is something that I want to auto-populate in SAS, which should start the counting from 1 when the value of Order ID changes. Please help me with the code.
Regards,
Rohit
data want;
set have;
by order_id;
if first.order_id then count_var=1;
else count_var+1;
run;
Data have;
input Order_ID;
datalines;
000123
000123
000123
000125
000125
000130
;
run;
proc sort;
by Order_ID;
run;
data want;
set have;
by Order_ID;
if first.Order_ID then Count_var=1;
else Count_var+1;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.