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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 97330 views
  • 9 likes
  • 3 in conversation