data want;
set have;
newvariable=cats('c_',_n_);
run;
... if I am understanding you properly
If I may be so bold as to point out a disadvantage of doing things this way ... NEWVARIABLE doesn't sort properly, if you sort NEWVARIABLE it will come out as
c_1
c_10
c_11
c_12
c_13
c_14
c_15
c_2
and so on
Why don't you just make newvariable numeric and assign it integers 1 through 15?
data want;
set have;
newvariable=cats('c_',_n_);
run;
... if I am understanding you properly
If I may be so bold as to point out a disadvantage of doing things this way ... NEWVARIABLE doesn't sort properly, if you sort NEWVARIABLE it will come out as
c_1
c_10
c_11
c_12
c_13
c_14
c_15
c_2
and so on
Why don't you just make newvariable numeric and assign it integers 1 through 15?
Or control the values a bit better:
data want;
set have;
newvariable=cats('c_',put(_n_, z2.));
run;
Assuming you know there are fewer than 100 records.
This gives you C_01, C_02, ... C_15.
Which will sort properly and, IMHO, looks a bit nicer.
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.