Help using Base SAS procedures

Extract Number from String?

Reply
N/A
Posts: 0

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: Extract Number from String?

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?

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

Ask a Question
Discussion stats
  • 3 replies
  • 21954 views
  • 2 likes
  • 3 in conversation