I have a dataset and in that a variable called var. In that i need extract observations which has a word "SOMETH". It may be first word or middle or last. Can you please explain me how to do it.
I tried var=:"SOMETH" but it only gives if the word comes first.
findw requires atleast 2 arguments but i only have one
@vraj1 wrote:
findw requires atleast 2 arguments but i only have one
Really?
You have
- a variable to search (var)
- a string to search for ('SOMETH')
So where's the problem?
data test;
var = 'This is a text with SOMETH in it';
result = findw(var,'SOMETH');
run;
proc print noobs; run;
Result:
var result This is a text with SOMETH in it 21
And if your value may sometimes have different case and you want to match "Someth", "someth" or even "someTH" as well as exactly "SOMETH" your comparison would need to consider case:
result = findw( upcase(var),'SOMETH')
Some actual concrete examples would help with input and desired result.
Note that your original search does not match "words".
See this example:
data example;
informat str $15.;
input str 1-15;
if str =: 'SOMETH' then put "Found" Str=;
datalines;
SOMETH
SOMETHing
Someth ELSE
something
;
run;
if index("SOMETH", var) > 0 then output;
Hello,
Sql Solution:
data have;
set sashelp.class;
if mod(_n_,4)=1 then name_new=cats(name)||'SOMETHetc etc';
else if mod(_n_,4)=2 then name_new=cats(name)||'SOMETHetc';
else if mod(_n_,4)=3 then name_new=name||'SOMETH';
else name_new=name;
run;
proc sql;
select * from have
where name_new like '%SOMETH%';
quit;
Use this function if your var has mixed case.
find(var,"SOMETH","i")
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 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.