Hey,
I'm trying to see if there is a specific value (in this case the letter "Y") after a set number of specific symbols (in this case in between the last 11 and 12 "|"s).
I tried to save the value in a new column and then doing an if statement, but the issue is that I do not know how to print the letter just before the last 11 |'s.
e.g.
data have; input params $70.; cards; |bla|||||5||bla|bla||||||bla||||bla|||||||Y||||||||||| |bla|||||10||bla|bla||||||bla||||bla|||||||Y|baa|||||||||| |bla|||||10||bla|bla||||||bla||||bla||||||||baa|||||||||| ; data want; set have; Want = substr(params, length(params)-11,1); run;
In this example i wanted it to print:
1: Y
2: Y
3: nothing
and not
1: Y
2: a
3: a
data have;
input params $70.;
cards;
|bla|||||5||bla|bla||||||bla||||bla|||||||Y|||||||||||
|bla|||||10||bla|bla||||||bla||||bla|||||||Y|baa||||||||||
|bla|||||10||bla|bla||||||bla||||bla||||||||baa||||||||||
;
data want;
set have;
call scan(params,-12,p,l,'|','mq');
want=substrn(params,p,l);
drop p l;
run;
data have;
input params $70.;
cards;
|bla|||||5||bla|bla||||||bla||||bla|||||||Y|||||||||||
|bla|||||10||bla|bla||||||bla||||bla|||||||Y|baa||||||||||
|bla|||||10||bla|bla||||||bla||||bla||||||||baa||||||||||
;
data want;
set have;
call scan(params,-12,p,l,'|','mq');
want=substrn(params,p,l);
drop p l;
run;
Wouldn't just "backward" scan() be good?
data want;
set have;
want = scan(params,-12,"|","M");
run;
Bart
SCAN() is better in this case since the request was just for the value between the delimiters, not the rest of the string.
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 lock in 2025 pricing—just $495!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.