11-03-2016 08:31 AM
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.
11-03-2016 08:36 AM - edited 11-03-2016 08:37 AM
11-03-2016 08:58 AM
findw requires atleast 2 arguments but i only have one
- 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;
var result This is a text with SOMETH in it 21
11-03-2016 10:57 AM - edited 11-04-2016 01:38 PM
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;
11-03-2016 08:54 AM
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;
11-03-2016 11:18 AM - edited 11-03-2016 11:18 AM
Use this function if your var has mixed case.