<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using FINDW in a DO loop to flag keywords in a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792634#M253970</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13901"&gt;@JackHamilton&lt;/a&gt;&amp;nbsp;said:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;If you had dozens or hundreds of keywords instead of half a dozen, it might be better to put the keywords and corresponding variable names into a SAS data set, and use a macro to generate the two ARRAY statements. DOSUBL might be even easier.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Why do you say that?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Also, you might want to look at the R or T modifier in the FINDW function as an alternative to using the TRIM function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I should have thought of that!&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jan 2022 19:03:55 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-01-26T19:03:55Z</dc:date>
    <item>
      <title>Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792567#M253953</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm about to cry because of SAS! I feel like I'm going crazy! Here's my issue: I want to create variables to flag specified keywords that are found in a TOPIC variable. Here's the code that I have:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data test ;
    format topics $char256. ; 
    infile datalines dsd dlm=":";
    input topics $ ;
    datalines;
PHYSICAL COMPUTING  BASIC COMPUTER TEACHING  PROJECTS USING WORD PROCESSING AND DATA ANALYZING  POWERPOINT
GAME DESIGN
WEB DESIGN AND DEVELOPMENT MOBILE APP DEVELOPMENT
PHYSICAL COMPUTING MAKER ACTIVITIES WEB DESIGN AND DEVELOPMENT TEXT-BASED PROGRAMMING
;
run;

%macro test() ; 
DATA test ;
    SET test ;

    array keywords [6] $ t1-t6 ('PHYSICAL', 'ACTIVITES', 'GAME', 'DATA', 'CODING', 'MOBILE') ;
    array varnames [6] physcomp makeract gamedesign datasci coding mobiledev ; 

    %do i = 1 %to 6 ;
        if findw(topics, keywords[&amp;amp;i]) &amp;gt; 0 then varnames[&amp;amp;i] = 1 ;
        else varnames[&amp;amp;i] = 0 ;
    %end ; 

RUN ;
%mend ; 

%test() ; &lt;/PRE&gt;&lt;P&gt;which produces the following data:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;PHYSICAL COMPUTING  BASIC COMPUTER TEACHING  PROJECTS USING WORD PROCESSING AND DATA ANALYZING  POWERPOINT	
1	0	0	0	0	0
GAME DESIGN	
0	0	0	0	0	0
WEB DESIGN AND DEVELOPMENT MOBILE APP DEVELOPMENT	
0	0	0	0	0	0
PHYSICAL COMPUTING MAKER ACTIVITIES WEB DESIGN AND DEVELOPMENT TEXT-BASED PROGRAMMING	
1	0	0	0	0	0&lt;/LI-CODE&gt;&lt;P&gt;Huh? Why isn't GAME in the second observation being recognized? Or MOBILE in the third observation? Why is PHYSICAL the only keyword being recognized? Please help, I'm at my wit's end!!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 17:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792567#M253953</guid>
      <dc:creator>jl13491</dc:creator>
      <dc:date>2022-01-26T17:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792570#M253954</link>
      <description>&lt;P&gt;Also, the order of the keyword/varnames list doesn't matter -- even if I put game design first, it still only recognizes physical computing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 17:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792570#M253954</guid>
      <dc:creator>jl13491</dc:creator>
      <dc:date>2022-01-26T17:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792608#M253957</link>
      <description>&lt;P&gt;I can't test and explore right now, but here's an idea to examine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you create character variables with an array the default length is 8.&amp;nbsp; So "GAME" is not the value "GAME&amp;nbsp; &amp;nbsp; " is the value.&amp;nbsp; I'm not sure how FINDW handles that, but you can easily find out.&amp;nbsp; Also note that some of your keywords are longer than 8 characters long, so the values are being chopped off.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 18:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792608#M253957</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-01-26T18:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792612#M253958</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/405237"&gt;@jl13491&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't worry, FINDW can really be confusing. Only minutes before I read your post I struggled with that function in a different context ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see three issues:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Length of array &lt;FONT face="courier new,courier"&gt;keywords&lt;/FONT&gt; is the default 8, so will truncate longer initial values. Use&amp;nbsp;
&lt;PRE&gt; array keywords [6] $&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;10&lt;/STRONG&gt;&lt;/FONT&gt; ...&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Typo "ACTIVI&lt;FONT color="#FF0000"&gt;TE&lt;/FONT&gt;S" in the second initial value.&lt;/LI&gt;
&lt;LI&gt;The trailing blanks of the keywords must be trimmed. Otherwise they become part of the search term (which is a problem for all keywords that are shorter than the defined length -- and the reason why "PHYSICAL" worked well with length 8). Use&lt;BR /&gt;
&lt;PRE&gt;findw(topics, &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;trim(&lt;/STRONG&gt;&lt;/FONT&gt;keywords[&amp;amp;i]&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;FONT color="#000000"&gt;)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 26 Jan 2022 18:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792612#M253958</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-01-26T18:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792613#M253959</link>
      <description>I LOVE YOU ASTOUNDING! Thank you for your big brain, you have cured me! Using TRIM(keywords[&amp;amp;i]) solved the issue!</description>
      <pubDate>Wed, 26 Jan 2022 18:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792613#M253959</guid>
      <dc:creator>jl13491</dc:creator>
      <dc:date>2022-01-26T18:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792614#M253960</link>
      <description>Thank you, Freelance, for the extremely thorough solution! You, like Outstanding, have saved me from SAS's horrific clutches! &lt;span class="lia-unicode-emoji" title=":red_heart:"&gt;❤️&lt;/span&gt;</description>
      <pubDate>Wed, 26 Jan 2022 18:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792614#M253960</guid>
      <dc:creator>jl13491</dc:creator>
      <dc:date>2022-01-26T18:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792615#M253961</link>
      <description>Astounding*</description>
      <pubDate>Wed, 26 Jan 2022 18:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792615#M253961</guid>
      <dc:creator>jl13491</dc:creator>
      <dc:date>2022-01-26T18:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792618#M253962</link>
      <description>&lt;P&gt;In addition to the above correct comments, you probably want to avoid using macros and macro variables when they are not necessary. Arrays contain all the features you need to do this, without macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test1;
    SET test ;
    array keywords [6] $ 10 _temporary_ ('PHYSICAL', 'ACTIVITIES', 'GAME', 'DATA', 'CODING', 'MOBILE') ;
    array varnames [6] physcomp makeract gamedesign datasci coding mobiledev; 
    do i = 1 to 6 ; 
        if findw(topics, trim(keywords[i]))&amp;gt; 0 then varnames[i] = 1 ; else varnames[i]=0;   
    end ; 
    drop i;
RUN ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jan 2022 18:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792618#M253962</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-26T18:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792633#M253969</link>
      <description>Unnecessarily putting code inside a macro is so common that there must be a flaw in how the macro language is taught.&lt;BR /&gt;&lt;BR /&gt;If you had dozens or hundreds of keywords instead of half a dozen, it might be better to put the keywords and corresponding variable names into a SAS data set, and use a macro to generate the two ARRAY statements.  DOSUBL might be even easier.  &lt;BR /&gt;&lt;BR /&gt;Also, you might want to look at the R or T modifier in the FINDW function as an alternative to using the TRIM function.</description>
      <pubDate>Wed, 26 Jan 2022 18:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792633#M253969</guid>
      <dc:creator>JackHamilton</dc:creator>
      <dc:date>2022-01-26T18:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792634#M253970</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13901"&gt;@JackHamilton&lt;/a&gt;&amp;nbsp;said:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;If you had dozens or hundreds of keywords instead of half a dozen, it might be better to put the keywords and corresponding variable names into a SAS data set, and use a macro to generate the two ARRAY statements. DOSUBL might be even easier.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Why do you say that?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Also, you might want to look at the R or T modifier in the FINDW function as an alternative to using the TRIM function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I should have thought of that!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 19:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792634#M253970</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-26T19:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792705#M254000</link>
      <description>Personally, I find it easier to maintain a long narrow list than a short wide list, and if the list is coming from an external source it's usually easier to read it in a data step than in a macro.  Data-driven instead of manually maintained array statements.&lt;BR /&gt;&lt;BR /&gt;Using DOSUBL lets me do the processing right where the list of values is needed, so I don't have to create global macro variables.  Depending on how much parameterization is needed, it might or might not be better than a macro.&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Jan 2022 23:33:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792705#M254000</guid>
      <dc:creator>JackHamilton</dc:creator>
      <dc:date>2022-01-26T23:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792706#M254001</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create a SAS data set containing words to be looked for and  */
/* their associated variables.                                  */

data mylist;
    input @1 lookfor $32.
         @34 varname $32. ;
datalines4;
PHYSICAL                         physcomp
ACTIVITIES                       makeract
GAME                             gamedesign
DATA                             datasci 
CODING                           coding
MOBILE                           mobiledev 
;;;;

/*** Method 1 ***/
/* Create global macro variables containing expanded parts of array statements.  */
%global lookfor_list varname_list list_length;

proc sql noprint;
    select 
        quote(trim(lookfor), "'") ,
        trim(varname) 
    into
        :LOOKFOR_LIST separated by ' ' ,
        :VARNAME_LIST separated by ' ' 
    from 
        mylist;
    %let list_length = &amp;amp;SQLOBS. ;
quit;

%put INFO: &amp;amp;=LOOKFOR_LIST ;
%put INFO: &amp;amp;=VARNAME_LIST ;
%put INFO: &amp;amp;=LIST_LENGTH  ;

data _null_; 
    array keywords [&amp;amp;LIST_LENGTH.] $32 _temporary_ (&amp;amp;LOOKFOR_LIST.) ;
    array varnames [&amp;amp;LIST_LENGTH.] 4 &amp;amp;VARNAME_LIST. ; 
    put keywords[1]=;
run;

%symdel lookfor_list varname_list list_length;

/*** Method 2 ***/
/* create global macro variables containing complete array statements.  */

%macro make_code();

    %global lookfor_code varname_code;
    %local lookfor_list varname_list list_length;
    
    proc sql noprint;
        select 
            quote(trim(lookfor), "'") ,
            trim(varname) 
        into
            :LOOKFOR_LIST separated by ' ' ,
            :VARNAME_LIST separated by ' ' 
        from 
            mylist;
        %let list_length = &amp;amp;SQLOBS. ;
    quit;
        
    %let lookfor_code = array keywords [&amp;amp;LIST_LENGTH.] $32 _temporary_ (&amp;amp;LOOKFOR_LIST.) ;
    %let varname_code = array varnames [&amp;amp;LIST_LENGTH.] 4 &amp;amp;VARNAME_LIST. ; 
    
    %put INFO: &amp;amp;=LOOKFOR_CODE;
    %put INFO: &amp;amp;=VARNAME_CODE;

%mend make_code;
%make_code();

data _null_; 
    &amp;amp;LOOKFOR_CODE. ;
    &amp;amp;VARNAME_CODE. ; 
    put keywords[1]=;
run;

%symdel lookfor_code varname_code;    
   
   
/*** Method 3 ***/
/* Create a macro that inserts code generated from SAS data set,    */
/* without causing a section break.  In real life, this would be    */
/* parameter-driven.                                                */

%macro use_dosub();

    %local lookfor_code varname_code;
    %local lookfor_list varname_list list_length;

    %let dosubl_rc = %sysfunc(dosubl(%nrstr(    
        proc sql noprint;
            select 
                quote(trim(lookfor), "'") ,
                trim(varname) 
            into
                :LOOKFOR_LIST separated by ' ' ,
                :VARNAME_LIST separated by ' ' 
            from 
                mylist;
            %let list_length = &amp;amp;SQLOBS. ;
        quit;
            
        %let lookfor_code = array keywords [&amp;amp;LIST_LENGTH.] $32 _temporary_ (&amp;amp;LOOKFOR_LIST.) ;
        %let varname_code = array varnames [&amp;amp;LIST_LENGTH.] 4 &amp;amp;VARNAME_LIST. ; 
    )));
    %put INFO: RC from &amp;amp;=DOSUBL_RC;

    %put INFO: &amp;amp;=LOOKFOR_CODE;
    %put INFO: &amp;amp;=VARNAME_CODE;    
    
    &amp;amp;LOOKFOR_CODE;
    &amp;amp;VARNAME_CODE;

%mend use_dosub;


data _null_; 
    %use_dosub(); 
    put keywords[1]=;
run;

%put _user_;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is using a sledgehammer for a penny nail, but sometimes the ability to create code inline without generating a section break is very useful.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 23:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792706#M254001</guid>
      <dc:creator>JackHamilton</dc:creator>
      <dc:date>2022-01-26T23:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792713#M254002</link>
      <description>&lt;P&gt;Here is example that remove macros.&lt;/P&gt;
&lt;P&gt;First create some sample datasets.&amp;nbsp; One with the list of strings to search and a second with the list of words to find.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test ;
  infile datalines truncover;
  row+1;
  input topics $256. ;
datalines;
PHYSICAL COMPUTING  BASIC COMPUTER TEACHING  PROJECTS USING WORD PROCESSING AND DATA ANALYZING  POWERPOINT
GAME DESIGN
WEB DESIGN AND DEVELOPMENT MOBILE APP DEVELOPMENT
PHYSICAL COMPUTING MAKER ACTIVITIES WEB DESIGN AND DEVELOPMENT TEXT-BASED PROGRAMMING
;

data keywords;
  key+1;
  input keyword $30.;
datalines;
PHYSICAL
ACTIVITIES
GAME
DATA
CODING
MOBILE
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then do a cross join to match every keyword to every string and then using FINDW() to check if the keyword is in the string.&lt;/P&gt;
&lt;P&gt;If you want the wide format then use PROC TRANSPOSE to create it.&amp;nbsp; If the goal is the wide structure then make the join a VIEW.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create view tall as 
  select a.*,b.*
       , 0&amp;lt;findw(topics,keyword,' ','sit') as found
  from test a
     , keywords b
  order by row,key
;
quit;

proc transpose data=tall out=want(drop=_name_) prefix=keyword;
  by row topics;
  id key;
  idlabel keyword;
  var found;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's check the results:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print;
 var row key: ;
run;

proc print label;
 var row key: ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-01-26 190925.jpg" style="width: 668px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67878iFDC852200A800366/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-01-26 190925.jpg" alt="Screenshot 2022-01-26 190925.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 00:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792713#M254002</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-27T00:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792716#M254003</link>
      <description>&lt;P&gt;I usually find that I need to train FINDW() to SIT for it be useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;H4 class="xisDoc-argument"&gt;i or I&lt;/H4&gt;
&lt;/BLOCKQUOTE&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;ignores the case of the characters.&lt;/P&gt;
&lt;DIV id="n0cs4nyh8z1ft2n10ydg89fpcg4p" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;s or S&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;adds space characters (blank, horizontal tab, vertical tab, carriage return, line feed, and form feed) to the list of characters.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;DIV id="p1okgzit5okmjqn1jzi4jshq3gee" class="xisDoc-argDescriptionPair"&gt;
&lt;BLOCKQUOTE&gt;
&lt;H4 class="xisDoc-argument"&gt;t or T&lt;/H4&gt;
&lt;/BLOCKQUOTE&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;trims trailing blanks from the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;string&lt;/EM&gt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;word&lt;/EM&gt;, and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;character&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;arguments.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 27 Jan 2022 00:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792716#M254003</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-27T00:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792809#M254038</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13901"&gt;@JackHamilton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Personally, I find it easier to maintain a long narrow list than a short wide list, and if the list is coming from an external source it's usually easier to read it in a data step than in a macro. Data-driven instead of manually maintained array statements.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Good explanation! Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 11:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792809#M254038</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-27T11:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using FINDW in a DO loop to flag keywords in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792827#M254041</link>
      <description>&lt;P&gt;Apart from Maxim 46 (Beware of the Hidden Blanks), you should also heed Maxim 11 (A Macro Is Not Needed) and, for the time being, forget that macros exist. You can and should then relearn this when you have mastered the basics of the SAS language, like DO loops in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input topics $256.;
datalines;
PHYSICAL COMPUTING  BASIC COMPUTER TEACHING  PROJECTS USING WORD PROCESSING AND DATA ANALYZING  POWERPOINT
GAME DESIGN
WEB DESIGN AND DEVELOPMENT MOBILE APP DEVELOPMENT
PHYSICAL COMPUTING MAKER ACTIVITIES WEB DESIGN AND DEVELOPMENT TEXT-BASED PROGRAMMING
;

data want;
set have;
array keywords [6] $ t1-t6 ('PHYSICAL','ACTIVITIES','GAME','DATA','CODING','MOBILE');
array varnames [6] physcomp makeract gamedesign datasci coding mobiledev; 
do _n_ = 1 to 6 ;
  if findw(topics, trim(keywords[_n_])) &amp;gt; 0 then varnames[_n_] = 1;
  else varnames[_n_] = 0;
end; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To become master of a tool, the most important thing to learn is when not to use it.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 12:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FINDW-in-a-DO-loop-to-flag-keywords-in-a-string/m-p/792827#M254041</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-27T12:30:39Z</dc:date>
    </item>
  </channel>
</rss>

