BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jacksonan123
Lapis Lazuli | Level 10

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.);
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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.);
--
Paige Miller
ballardw
Super User

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.

Krueger
Pyrite | Level 9
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; 
Tom
Super User Tom
Super User

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,'.'))

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1086 views
  • 0 likes
  • 5 in conversation