Help using Base SAS procedures

Extract Number from String?

Accepted Solution Solved
Reply
N/A
Posts: 0
Accepted Solution

Extract Number from String?

Seems like there should be an easy enough solution for this...I have just had difficulting thinking of the words to find that solution.

Example: I'd like to take the class list below and extract the numeric values from the string variables.

MATH400
BUS450
SCI310a
SCI310b
HIST299

Output
400
450
310
310
299

Is there an easy way to do this?


Thanks.

Accepted Solutions
Solution
‎09-01-2017 10:30 AM
Super Contributor
Super Contributor
Posts: 3,174

Re: Extract Number from String?

Posted in reply to deleted_user
In a DATA step, use the COMPRESS function in a SAS variable assignment statement to eliminate the non-numeric characters, and use UPCASE to convert lower to uppercase to reduce the list of variables specified in the COMPRESS function argument list.

Scott Barry
SBBWorks, Inc.

View solution in original post


All Replies
Solution
‎09-01-2017 10:30 AM
Super Contributor
Super Contributor
Posts: 3,174

Re: Extract Number from String?

Posted in reply to deleted_user
In a DATA step, use the COMPRESS function in a SAS variable assignment statement to eliminate the non-numeric characters, and use UPCASE to convert lower to uppercase to reduce the list of variables specified in the COMPRESS function argument list.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Extract Number from String?

That works great. I just used

CourseNum = compress(CourseCode, ' ', 'A')

The third parameter, 'A' gets rid of all (A-Z) and (a-z) ...while the second parameter, ' ', does nothing other than hold space for the third parameter.

Thanks a ton.
Johnny
Contributor
Posts: 27

Re: Extract Number from String?

Posted in reply to deleted_user

Can I do the same in the JMP Formula editor? Extract a number from a string that is.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 25069 views
  • 2 likes
  • 3 in conversation