i have a data of 5000 companies which are repeated for multiple number of times.
I want to code each company as comp1, comp2, comp3 etc.,
the sample of the file is as follows
the desired output should be like this
thanks in advance
Use a retained variable:
data want; set have; by company; retain comp_count 0; if first.company then comp_count + 1; code = cats('comp',comp_count); drop comp_count; run;
data have; input company $; cards; a a a a a b b b b b c c c c c ; data want; do until(last.company); set have; by company; length code $10; code=cats('COMP',_n_); output; end; run;
A good idea, but it can be done with a slightly quicker program:
data want; length code $ 10; code = cats('comp', _n_); do until (last.company); set have; by company; output; end; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Save the date!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.