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

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