BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
J_J_J
Obsidian | Level 7

Hi!

Can anybody help me please to find in a string numbers (successively). It can be different count of digits on different lines.

Example:

1) text #11111111# text

2) text

3) text #555555555# text

 

I would like to get 2 rows:

1) 1111111

2) 555555555

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Ok. Building on your previous thread, how about this?

 

data have;
input string $ 1-50;
datalines;
text #11111111# text
text
text #555555555# text
;

data want;
    set have;
    num=input(prxchange('s/.*#(\d+)#.*/\1/', -1, string), 8.);
    if num;
run;

Result:

 

string                   num
text #11111111# text     11111111
text #555555555# text    55555555

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Do you simply want to extract numbers (0123456789) from a string or do they have to be enclosed in ##?

J_J_J
Obsidian | Level 7

They have to be enclosed in ##

PeterClemmensen
Tourmaline | Level 20

Ok. Building on your previous thread, how about this?

 

data have;
input string $ 1-50;
datalines;
text #11111111# text
text
text #555555555# text
;

data want;
    set have;
    num=input(prxchange('s/.*#(\d+)#.*/\1/', -1, string), 8.);
    if num;
run;

Result:

 

string                   num
text #11111111# text     11111111
text #555555555# text    55555555
J_J_J
Obsidian | Level 7

Thanks a lot! It works!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1083 views
  • 1 like
  • 2 in conversation