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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: