Hi sas experts, I have a dataset
data example;
input var1 var2 var3;cards;
01 MAP 0
01 MAP 1
01 CVP 0
01 CVP 1
01 CVP 2
01 GCS 0
01 GCS 1
01 HR 0
01 HR 1
02 MAP 0
02 MAP 1
02 MAP 2
02 MAP 3
02 CVP 0
02 CVP 1
02 CVP 2
02 CVP 3
02 GCS 0
02 GCS 1
02 HR 0
02 HR 1
02 HR 2
03 MAP 0
03 MAP 1
03 CVP 0
03 GCS 0
;run;
in the dataset i have numerical ordering variable (var3) for by each var1 var2, its a sorted dataset. I want to create a new variable where i can assign values such as: form 01 to last category obs of var1(084 in my actual dataset), any no of times MAP appears in the observation the newvar= would be 1 and similarly CVP=2, GCS=3, HR=4.
please suggest how to solve this using do loop. Also it would be really helpful if any expert could guide for adding a counter in loop for the below code, as it works only for 01 and MAP and for other observations it simply takes the row number.
data nDATA; set example; retain newvar; by var1 var2; if first.var2 then newvar=_n_; output; run;
... View more