BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
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.
1 ACCEPTED SOLUTION

Accepted Solutions
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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

3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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
JesperJohansen
Calcite | Level 5

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 100567 views
  • 9 likes
  • 3 in conversation