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
https://documentation.sas.com/doc/en/vdmmlcdc/8.1/lefunctionsref/p0jshdjy2z9zdzn1h7k90u99lyq6.htm
Scan using parens and comma as delimiters.
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, '(),' );
Probably should ask if a numeric result is desired so the appropriate INPUT could be added.
Thank you @pink_poodle and @WarrenKuhfeld @ballardw
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.