If I have a character value called epspropl=45.5c and I convert it to a numeric by:
vepspropl=input (epspropl,8.);
My question is since it contains an alphabetic character c, is there a way to convert epspropl to a numeric and get rid of the unwanted c or do I have to do something else to get rid of the c?
You could use the COMPRESS() function to get rid of all characters before you use the INPUT function. The 'a' modifier of the compress function eliminates characters but not numbers or decimals.
vepspropl=input (compress(epspropl,,'a'),8.);
You could use the COMPRESS() function to get rid of all characters before you use the INPUT function. The 'a' modifier of the compress function eliminates characters but not numbers or decimals.
vepspropl=input (compress(epspropl,,'a'),8.);
One way:
data example; epspropl="45.5c"; vepspropl=input (compress(epspropl,,'a'),8.); run;
compress removes characters from a string. In this case it removes all alphabetic. If you don't want that and only want a c removed
data example; epspropl="45.5c"; vepspropl=input (compress(epspropl,'c','i'),8.); run;
the 'i' says to ignore case when removing c, so would remove both upper and lower case c's.
data have;
input a $2. b $3. c $3.;
datalines;
1a 2b 3c
;
run;
data want;
set have;
test = input(compress(a, '', 'a'), 2.);
run;
You have to do something to tell INPUT() not to read the letter.
So you could remove the C from the string using say COMPRESS(). Like compress(epspropl,'c').
If it is just the last character you could use SUBSTR() or the informat.
Like substr(epspropl,1,length(epspropl)-1).
Or just tell it to only use the first 4 characters. Like: input(epspropl,4.) or INPUTN(epspropl,cats(length(epspropl)-1,'.'))
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.