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.);

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1662 views
  • 8 likes
  • 4 in conversation