Hi,
I have a variable which has value like 'XZ_VAC_901' in character format.
I have to convert this to numeric. Can anyone help ?
Are they all this exact structure?
I would use compress to remove anything but digits and then use compress. If you have decimal points this may not work.
data demo;
length value_char $15.;
value_char= 'XZ_VAC_901';
value_numeric = input(compress(value_char, , 'kd'), 8.);
run;
proc print data=demo;
run;
@r3570 wrote:
Hi,
I have a variable which has value like 'XZ_VAC_901' in character format.
I have to convert this to numeric. Can anyone help ?
My requirement was just to change the data type to numeric from character.
There is no requirement to separate out the numbers and characters.
I just need the variable type to be converted to numeric retaining the values in the variable as such.
XZ_VAC_901 (char) to XZ_VAC_901 (num)
The whole table has the values in same format as provided in above example.
If you can help with that it would be great.
"XZ_VAC" is (very obviously) not a number, so this is not possible as such.
If you have a limited, predefined scope of possible values, you could encode them in numbers and use a format to display the characters.
Hi,
I have a variable which has value like 'XZ_VAC_901' in character format.
I have to convert this to numeric. Can anyone help ?
My requirement was just to change the data type to numeric from character.
There is no requirement to separate out the numbers and characters.
I just need the variable type to be converted to numeric retaining the values in the variable as such.
XZ_VAC_901 (char) to XZ_VAC_901 (num)
The whole table has the values in same format as provided in above example.
If anyone can help with this it would be great.
@r3570 wrote:
Hi,
I have a variable which has value like 'XZ_VAC_901' in character format.
I have to convert this to numeric. Can anyone help ?
My requirement was just to change the data type to numeric from character.
There is no requirement to separate out the numbers and characters.
I just need the variable type to be converted to numeric retaining the values in the variable as such.
XZ_VAC_901 (char) to XZ_VAC_901 (num)
The whole table has the values in same format as provided in above example.
If anyone can help with this it would be great.
XZ_VAC are not numerals or digits so what you ask makes no sense whatsoever. Any character other than 123456789 and decimal, except in the case of E for exponential notation or ABCDEF for hexadecimal values, or ROMAN numerals where _ZA901 are not numerals) are not numbers. Period.
If someone has given you this requirement then ask them what the numeric value is.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.