In SAS I'd like to add id values to the variables with a specific conditions. I have the following code:
DATA market_new;
SET sashelp.cars;
if Make = 'Audi' then id = 0;
else id = _N_;
RUN;
proc print data=market_new;
run;
Output:
The problem is that the id continues with 27, 28 etc. after the make isn't equal to Audi. My goal is to have 8, 9 instead.
Use a SUM
(+
) statement to track the Audis.
if make='Audi' then do;
audi_seq + 1; drop audi_seq;
audi_id = audi_seq;
end;
else
audi_id = 0;