Hi
When using PROC SQL, there is operator for 'contains' in addition to equals. Is there a way to use 'contains' functionality in a data step? I have the below data step that I apparently need to use something like 'contains' as there are data values that are not returned, but look exactly like those that are returned when using equals (possible spaces after 'Issue Joined', maybe).
Paul
data work.issuejoinedevents;
set sasD.court_events;
if event_detail_1 = 'Issue Joined';
run;
Use the INDEX function
If Index function returns a number > 0, then it "contains" the desired text.
If Index function returns a zero, then it does not "contain" the desired text.
Use the INDEX function
If Index function returns a number > 0, then it "contains" the desired text.
If Index function returns a zero, then it does not "contain" the desired text.
I think that did it, thank you.
Paul
The suggestion about INDEX is spot on. Just to help you understand, though, trailing blanks would not cause a problem. Other situations would, such as (1) leading blanks, (2) spelling/capitalization differences, or (3) other trailing characters such as carriage returns/line feeds if they appear in the data.
Goood luck.
Paul,
You might find the findw function to have some additional features you might want/need. Take a look at: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002978282.htm
INDEX is more general than FINDW, which as I understand it searches for words, while INDEX can search for arbitrary character strings
INDEX can be configure to ignore case as well
Yes, that's what I meant
Paige, I sit corrected! I just did a comparison and, to my surprize, combining functions using the index function ran twice as fast as using the findw function.
I ran:
data class;
set sashelp.class;
do _n_=1 to 100000;
output;
end;
run;
data want;
set class;
x=findw(name,'AN',,'iks');
run;
data want;
set class;
x=index(upcase(name),'AN');
run;
Good to know. I wasn't even claiming a speed advantage, I just think INDEX is easier to program and easier to read than FINDW in this application.
A more recently function is FIND() which is better than INDEX() , bescause it has more arguments than INDEX() ,has more power .
So if you want , you can use FIND() replace INDEX().
Ksharp
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.