<?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 Macro Do Loops in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/488674#M72028</link>
    <description>&lt;P&gt;Hi Guys!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm in a little pickle here. Let me explain....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The overall project is to take information from the variable columns and give then a weight then score. However, there are so many variables to weigh and score that it would be really tedious to do each one individually. I am looking for a macro paired with do loops to process this data in short, efficient code. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=have&lt;BR /&gt;&amp;nbsp;out=want;&lt;BR /&gt;&amp;nbsp;by&amp;nbsp;id&amp;nbsp;year descending doc_num;&lt;BR /&gt;&amp;nbsp;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp;set have(where=(year=&amp;amp;curryr.&amp;nbsp;or year=&amp;amp;prevyr. and doc_num=&amp;amp;.));&lt;/P&gt;&lt;P&gt;by id;&lt;BR /&gt;&amp;nbsp;if name then a_weight = 'L' and a_score='L';&lt;BR /&gt;&amp;nbsp;if first.sale_dt = . and last.sale_dt = . then weight='M' and score='M';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;else if first.sale_dt is not . and last.sale_dt = . then weight='M' and score='L';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;else if first.sale_dt = . and last.sale_dt is not . then weight = 'M' and score='L';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;else if first.sale_dt ^= last.sale_dt then weight='M' and score='M';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;else if first.sale_dt = last.sale_dt then weight='M' and score='L';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other variables and weights will be different than above, but the expressions will stay the same.....&lt;/P&gt;&lt;P&gt;For instance:&amp;nbsp;if price is missing on both days then weight&amp;nbsp;='L' and score='L' and so on.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if product is missing on both days then weight='M' and score='L' and so on....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final objective is to&amp;nbsp;put the weight and score through a calculation (adding up all of the scores with a corresponding number) to get the&amp;nbsp;total document score.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;Suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Aug 2018 13:29:48 GMT</pubDate>
    <dc:creator>DrBigAl</dc:creator>
    <dc:date>2018-08-22T13:29:48Z</dc:date>
    <item>
      <title>Macro Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/488674#M72028</link>
      <description>&lt;P&gt;Hi Guys!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm in a little pickle here. Let me explain....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The overall project is to take information from the variable columns and give then a weight then score. However, there are so many variables to weigh and score that it would be really tedious to do each one individually. I am looking for a macro paired with do loops to process this data in short, efficient code. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=have&lt;BR /&gt;&amp;nbsp;out=want;&lt;BR /&gt;&amp;nbsp;by&amp;nbsp;id&amp;nbsp;year descending doc_num;&lt;BR /&gt;&amp;nbsp;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp;set have(where=(year=&amp;amp;curryr.&amp;nbsp;or year=&amp;amp;prevyr. and doc_num=&amp;amp;.));&lt;/P&gt;&lt;P&gt;by id;&lt;BR /&gt;&amp;nbsp;if name then a_weight = 'L' and a_score='L';&lt;BR /&gt;&amp;nbsp;if first.sale_dt = . and last.sale_dt = . then weight='M' and score='M';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;else if first.sale_dt is not . and last.sale_dt = . then weight='M' and score='L';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;else if first.sale_dt = . and last.sale_dt is not . then weight = 'M' and score='L';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;else if first.sale_dt ^= last.sale_dt then weight='M' and score='M';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;else if first.sale_dt = last.sale_dt then weight='M' and score='L';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other variables and weights will be different than above, but the expressions will stay the same.....&lt;/P&gt;&lt;P&gt;For instance:&amp;nbsp;if price is missing on both days then weight&amp;nbsp;='L' and score='L' and so on.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if product is missing on both days then weight='M' and score='L' and so on....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final objective is to&amp;nbsp;put the weight and score through a calculation (adding up all of the scores with a corresponding number) to get the&amp;nbsp;total document score.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;Suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 13:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/488674#M72028</guid>
      <dc:creator>DrBigAl</dc:creator>
      <dc:date>2018-08-22T13:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/488677#M72029</link>
      <description>&lt;P&gt;A macro can generate all the code you might need, but you can't do that yet.&amp;nbsp; First, you must have working code for one individual case.&amp;nbsp; Then you can contemplate using a macro to expand that to many cases ... if a macro is needed.&amp;nbsp; But the program that you posted is not working code. So get it working first, then we can talk about the next step.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 19:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/488677#M72029</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-21T19:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/488706#M72030</link>
      <description>&lt;P&gt;You do realize that this snippet of code&lt;/P&gt;
&lt;PRE&gt; set have(where=(year=&amp;amp;curryr. and year=&amp;amp;prevyr.&lt;/PRE&gt;
&lt;P&gt;is only going to have any output records when &amp;amp;curryr = &amp;amp;prevyr don't you? In which case why are there two comparisons?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want records when the value of the year variable is either &amp;amp;curryr. &lt;STRONG&gt;or &lt;/STRONG&gt;&amp;amp;prevyr?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 20:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/488706#M72030</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-21T20:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/488740#M72033</link>
      <description>I am comparing records from this year and last year. I would only want the records for 2017 and 2018. So or is correct.&lt;BR /&gt;&lt;BR /&gt;I couldn't test the code because I only have table names. Data hasn't been loaded as of yet. I really just need to map things out with a plan until the data is loaded</description>
      <pubDate>Tue, 21 Aug 2018 23:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/488740#M72033</guid>
      <dc:creator>DrBigAl</dc:creator>
      <dc:date>2018-08-21T23:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/488926#M72040</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/186353"&gt;@DrBigAl&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I am comparing records from this year and last year. I would only &lt;STRONG&gt;want the records for 2017 and 2018&lt;/STRONG&gt;. So or is correct.&lt;BR /&gt;&lt;BR /&gt;I couldn't test the code because I only have table names. Data hasn't been loaded as of yet. I really just need to map things out with a plan until the data is loaded&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Instead of the "AND" which will &lt;STRONG&gt;not&lt;/STRONG&gt; select any records look at&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;year in (&amp;amp;curryr.&amp;nbsp; &amp;amp;prevyr.)&lt;/P&gt;
&lt;P&gt;which is an OR condition.&lt;/P&gt;
&lt;P&gt;Please examine the results of this code and see which one you want. This will be have exactly the same as your "where" logic for the year variable.&lt;/P&gt;
&lt;PRE&gt;data example;
   curryr = 2017;
   prevyr = 2018;
   year = 2017;
   if year=2017 and year=2018 then value= 'Yes Match';
   else value= 'No Match';
   if year in (2017 2018) then oth = 'Yes Match';
   else oth = 'No Match';

run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 15:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/488926#M72040</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-22T15:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/489011#M72054</link>
      <description>&lt;P&gt;Thank you! This helped me refocus my efforts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 19:15:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-Do-Loops/m-p/489011#M72054</guid>
      <dc:creator>DrBigAl</dc:creator>
      <dc:date>2018-08-22T19:15:24Z</dc:date>
    </item>
  </channel>
</rss>

