The FINDW function is returning smaller count of observations compared to the dataset. e.g) The code returns a freq of 5 for adherence but the actual count is 8 in the dataset. Below is my code:
IF FINDW (upcase(SocialEmotinalStress),upcase('Unstable Housing'))>0 THEN BS_Housing=1; ELSE BS_Housing=0;
IF FINDW (SocialEmotinalStress,'Adherence')>0 THEN BS_Adherence=1; ELSE BS_Adherence=0;
IF FINDW (SocialEmotinalStress,'Chronic Disease')>0 THEN BS_Chronic=1; ELSE BS_Chronic=0;
IF FINDW (SocialEmotinalStress,'Social Support/Isolation')>0 THEN BS_Social=1; ELSE BS_Social=0;
IF FINDW (SocialEmotinalStress,'Lack of Access/Financial Resources')>0 THEN BS_Access=1; ELSE BS_Access=0;
IF FINDW (upcase(SocialEmotinalStress),upcase('Medical Condition'))>0 THEN BS_Medical=1; ELSE BS_Medical=0;
IF FINDW (SocialEmotinalStress,'Mental Health Conditions')>0 THEN BS_Mental=1; ELSE BS_Mental=0;
IF FINDW (SocialEmotinalStress,'Other')>0 THEN BS_Other1=1; ELSE BS_Other1=0;
IF FINDW (SocialEmotinalStress,'Trauma')>0 THEN BS_Trauma=1; ELSE BS_Trauma=0;
IF FINDW (SocialEmotinalStress,'Stressor')>0 THEN BS_Stressor=1; ELSE BS_Stressor=0;
IF FINDW (SocialEmotinalStress,'Violence and intimate partner violence (IPV)')>0 THEN BS_IPV=1; ELSE BS_IPV=0;
@bn820 - Please update your post as answered in that case.
Please share a portion of the data you are using, along with the desired output for this portion of the data. Please provide the data as working SAS data step code (examples and instructions); and do not provide the data in other forms.
You are searching for multiple word matches but using the single word function search FINDW. Try FIND or INDEX instead.
@SASKiwi wrote:
You are searching for multiple word matches but using the single word function search FINDW. Try FIND or INDEX instead.
FINDW works fine for finding multiple word matches. As long as the words are in the same order with the separation between the words in the string being searched as they appear in the strings being looked for.
So
findw('a b c d e','b c',' ')
Will find 'b c' in 'a b c d e'.
But
findw('a b c d e','b c',' ')
Will not match.
array _words(3) _temporary_ $50. ('Unstable Housing', 'Adherence', 'Chronic Disease'); *Fill in rest of terms;
array _BS(3) BS_housing bs_adherence bs_chronic; *fill in rest of variables;
do i=1 to dim(_words);
IF FIND (SocialEmotinalStress, _words(i), 'it')>0 THEN _bs(i)=1; ELSE _bs(i)=0;
end;
Modifiers (i/t)
ignores character case during the search. If this modifier is not specified, FIND searches only for character substrings with the same case as the characters in substring.
@bn820 wrote:
The FINDW function is returning smaller count of observations compared to the dataset. e.g) The code returns a freq of 5 for adherence but the actual count is 8 in the dataset. Below is my code:
IF FINDW (upcase(SocialEmotinalStress),upcase('Unstable Housing'))>0 THEN BS_Housing=1; ELSE BS_Housing=0;
IF FINDW (SocialEmotinalStress,'Adherence')>0 THEN BS_Adherence=1; ELSE BS_Adherence=0;
IF FINDW (SocialEmotinalStress,'Chronic Disease')>0 THEN BS_Chronic=1; ELSE BS_Chronic=0;
IF FINDW (SocialEmotinalStress,'Social Support/Isolation')>0 THEN BS_Social=1; ELSE BS_Social=0;
IF FINDW (SocialEmotinalStress,'Lack of Access/Financial Resources')>0 THEN BS_Access=1; ELSE BS_Access=0;
IF FINDW (upcase(SocialEmotinalStress),upcase('Medical Condition'))>0 THEN BS_Medical=1; ELSE BS_Medical=0;
IF FINDW (SocialEmotinalStress,'Mental Health Conditions')>0 THEN BS_Mental=1; ELSE BS_Mental=0;
IF FINDW (SocialEmotinalStress,'Other')>0 THEN BS_Other1=1; ELSE BS_Other1=0;
IF FINDW (SocialEmotinalStress,'Trauma')>0 THEN BS_Trauma=1; ELSE BS_Trauma=0;
IF FINDW (SocialEmotinalStress,'Stressor')>0 THEN BS_Stressor=1; ELSE BS_Stressor=0;
IF FINDW (SocialEmotinalStress,'Violence and intimate partner violence (IPV)')>0 THEN BS_IPV=1; ELSE BS_IPV=0;
Thanks everyone! These were vryhelpful
@bn820 - Please update your post as answered in that case.
Sorry. I am new to SAS community. I am still learning.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.