Good day! here is my data
data samp1;
input treeno nob b1-b3;
cards;
1 10 11 12
2 13 14 15
3 16 17 18
;
and it prints as
treeno b1 b2 b3
1 10 11 12
2 13 14 15
3 16 17 18
what i would want to do is replace b1 to b3 as just numbers 1 to 3. could you pls help me? thanks
SAS variables must follow naming rules and one of these rules states that a SAS variable name must start with an underscore or letter.
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000998953.htm
You can assign labels to variables for printing. See below:
data sample1;
input treeno b1-b3;
label b1='1' b2='2' b3='3';
cards;
1 10 11 12
2 13 14 15
3 16 17 18
;
run;
proc print data=sample1 noobs label;
run;
You prolly need to use String literal after setting
options validvarname=any;
data samp1;
input treeno nob b1-b3;
cards;
1 10 11 12
2 13 14 15
3 16 17 18
;
data want;
set samp1;
rename b1='1'n b2='2'n b3='3'n ;
run;
Regards,
Naveen Srinivasan
As Naveen says you need to use 'options validvarname=any' but you don't need the rename step. This will work just as well
options validvarname=any;
data samp1;
input treeno "1"n-"3"n;
cards;
1 10 11 12
2 13 14 15
3 16 17 18
;
run;
proc print data=samp1;
run;
I must say though that validvarname =any is usually used when handling data from an external source such as an RDBMS or Excel when normal SAS naming rules don't apply. If you start down the route of using this option you'll have to use it in every piece of code which references this file.
"...you'll have to use it in every piece of code which references this file"
And that's why I've proposed to use labels and didn't even mention SAS name literals for variable names (they are to be avoided).
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.