Hello,
I need to create a new variable that adds the character “_" in front of the value of an existing variable. I find this easy to do in Excel, but I cannot do it in SAS.
An example:
This is what I have
data have ; input date va vb $;
cards ;
20000630 6.1207 to
20000929 6.1158 ri
20001229 5.7898 to
20010330 4.9815 co
;
run;
I need to generate new variable _va that adds _ to the values of the existing variable va.
So, I would like to have this:
data want
Date va _va vb
20000630 6.1207 _6.1207 to
20000929 6.1158 _3.1158 ri
20001229 5.7898 _5.7898 to
20010330 4.9815 _4.9815 co
Thank you for your help
Certainly much easier to do in SAS than in Excel. No pointing or clicking required.
data want;
set have;
length _va $15 ;
_va=cats('_',va);
run;
You can also use the PUT() function to control how the number is converted to a string.
If you know VA should have positive values values less than 10 then you probably want to use the 6.4 format.
data want;
set have;
length _va $7;
_va=cats('_',put(va,6.4));
run;
Thank you Tom !!
I am curious: what is the use-case requiring numeric values being prefixed with an underscore?
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.