<?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 Let Statement in a Do Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211410#M39140</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Macro variables in a data step are generally created using call symput, not %let. You can use %let if you use macro loops and other logic but this is too much work. &lt;/P&gt;&lt;P&gt;2. Macro variables created in a data step are generally not available in the same data step. You can get around this in various ways using resolve() function but it's too much work in my opinion.&lt;/P&gt;&lt;P&gt;3. Your assignment to O works out to be a variable assignment - O=Director when you actually need quotation marks - O="&amp;amp;i" assuming the other logic was correct. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 May 2015 17:53:01 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-05-07T17:53:01Z</dc:date>
    <item>
      <title>Using Let Statement in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211406#M39136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, I am doing some text processing and cleaning, and have got this little issue.&amp;nbsp; I want to omit the words 'director' or 'officer' (and a lot more words) from the variable name.&lt;/P&gt;&lt;P&gt;For this, I create the do loop, which goes through the list of words and omits them from the variable. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what I want to add, is to save the omitted word in another variable, so I know what was the omitted one. For example, if the name is GARY OFFICER, then the varibale name_h would be just GARY, and variable O would be OFFICER. This is why I define the let statement in the do loop, so that it saves the list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code, however, is not working correctly, and I am thinking that probably my use of let statement is not correct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone please help me on that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here's the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA have; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; INPUT name $1-30; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; DATALINES; &lt;/P&gt;&lt;P&gt; GARRY OFFICER&lt;/P&gt;&lt;P&gt; PATRICK DIRECTOR&lt;/P&gt;&lt;P&gt; JOHN&lt;/P&gt;&lt;P&gt;; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; data want (drop = list);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; name_h = name;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do list = 'DIRECTOR','OFFICER';&lt;/P&gt;&lt;P&gt;&amp;nbsp; % let i = list;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if index(strip(name_h),list) &amp;gt; 0 then O = &amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp; name_h = tranwrd(strip(name_h),strip(list),'');&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 May 2015 16:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211406#M39136</guid>
      <dc:creator>Shayan2012</dc:creator>
      <dc:date>2015-05-07T16:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using Let Statement in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211407#M39137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'd recommend using a temporary array and looping over that instead:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;data want (drop = list);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;array search(2) $ _temporary_ ('DIRECTOR', 'OFFICER');&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; name_h = name;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; do i=1 to dim(search);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; list=search(i);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; if index(strip(name_h),strip(list)) &amp;gt; 0 then O = list;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; name_h = tranwrd(strip(name_h),strip(list),'');&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;If you have your list i.e. Director/Officer in a dataset there are ways to load that into a temporary array using a data step. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 May 2015 17:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211407#M39137</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-05-07T17:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using Let Statement in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211408#M39138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Adding to the above answer ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There's no need to complicate what you are doing with a macro variables here, data step variables work fine.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 May 2015 17:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211408#M39138</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-05-07T17:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using Let Statement in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211409#M39139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot, Reeza.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That works perfectly. But, for my understanding, could you please let me know why my code does not work properly?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 May 2015 17:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211409#M39139</guid>
      <dc:creator>Shayan2012</dc:creator>
      <dc:date>2015-05-07T17:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using Let Statement in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211410#M39140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Macro variables in a data step are generally created using call symput, not %let. You can use %let if you use macro loops and other logic but this is too much work. &lt;/P&gt;&lt;P&gt;2. Macro variables created in a data step are generally not available in the same data step. You can get around this in various ways using resolve() function but it's too much work in my opinion.&lt;/P&gt;&lt;P&gt;3. Your assignment to O works out to be a variable assignment - O=Director when you actually need quotation marks - O="&amp;amp;i" assuming the other logic was correct. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 May 2015 17:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211410#M39140</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-05-07T17:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using Let Statement in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211411#M39141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DATA have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; INPUT name $1-30;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; DATALINES;&lt;/P&gt;&lt;P&gt;GARRY OFFICER&lt;/P&gt;&lt;P&gt;PATRICK DIRECTOR&lt;/P&gt;&lt;P&gt;JOHN&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt; set have;&lt;/P&gt;&lt;P&gt; g=prxchange('s/OFFICER|DIRECTOR//io',-1,name);&lt;/P&gt;&lt;P&gt; if prxmatch('/OFFICER|DIRECTOR/',name) then o=prxchange('s/.*(OFFICER|DIRECTOR).*/$1/io',-1,name);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 May 2015 14:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Let-Statement-in-a-Do-Loop/m-p/211411#M39141</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-05-08T14:59:33Z</dc:date>
    </item>
  </channel>
</rss>

