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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.