BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

I would like to substring a string dynamically. in the following example I have to separate each number (x and y) coordinates from the 'text' string 'xy(x,y)' 

 

data have;
 input x $25.;
cards;
'xy(1,1)'
'xy(1,10)'
'xy(10,1)'
'xy(10,10)'
'xy(100,1)'
;
run;

output Want 

 

text                     x           y

'xy(1,1)'                      1            1
'xy(1,10)'                    1            10
'xy(10,1)'                    10          1
'xy(10,10)'                  10          10
'xy(100,1)'                  100         1

 

Thank you for your inputs

1 ACCEPTED SOLUTION

Accepted Solutions
pink_poodle
Barite | Level 11
x = input( scan( text, 2, “(),” ), 8.);
y = input( scan( text, 3, “(),” ), 8.);

View solution in original post

5 REPLIES 5
pink_poodle
Barite | Level 11

Thank you, @WarrenKuhfeld! The text string does not need quotation marks. Third argument in quotes lists delimiters.
x = scan( text, 2, '(),' );
y = scan( text, 3, '(),' );


ballardw
Super User

Probably should ask if a numeric result is desired so the appropriate INPUT could be added.

pink_poodle
Barite | Level 11
x = input( scan( text, 2, “(),” ), 8.);
y = input( scan( text, 3, “(),” ), 8.);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 5 replies
  • 1459 views
  • 8 likes
  • 4 in conversation