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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.