<?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: How do I fix my macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/252877#M268820</link>
    <description>&lt;P&gt;If your data goes from 9 to 15 why are you looping from 1 to 7?&lt;/P&gt;
&lt;P&gt;Loop from 9 to 15 and use z2. Format so that the 9 converts to 09.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On top of the solution to add %end.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 27 Feb 2016 01:45:04 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-02-27T01:45:04Z</dc:date>
    <item>
      <title>How do I fix my macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/252856#M268818</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a macro for this calculation I am doing for several datasets but just can't seem to get my code to work.&amp;nbsp; Here's some information you might need if you want to help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Library name: Diabetes&lt;/P&gt;&lt;P&gt;Datasets = FFYEAR09 FFYEAR10 FFYEAR11 FFYEAR12 FFYEAR13 FFYEAR14 FFYEAR15&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the original code I want to use in a macro; it works when I do it individually for a dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; DIABETES.FFYEAR09 (KEEP=RECIPIENT_NBR ALLMEDS TOTALQNT OCTMEDS OCTQNT);&lt;/P&gt;&lt;P&gt;SET DIABETES.FFYEAR09;&lt;/P&gt;&lt;P&gt;BY RECIPIENT_NBR NDC;&lt;/P&gt;&lt;P&gt;RETAIN ALLMEDS TOTALQNT OCTMEDS OCTQNT;&lt;/P&gt;&lt;P&gt;IF FIRST.RECIPIENT_NBR THEN DO;&lt;/P&gt;&lt;P&gt;ALLMEDS = &lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;TOTALQNT = &lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;OCTMEDS = &lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;OCTQNT = &lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;IF FIRST.NDC THEN DO;&lt;/P&gt;&lt;P&gt;ALLMEDS + &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;TOTALQNT + RX_QUANTITY;&lt;/P&gt;&lt;P&gt;IF MONTH (RX_FILL_DT) = &lt;STRONG&gt;10&lt;/STRONG&gt; THEN DO;&lt;/P&gt;&lt;P&gt;OCTMEDS + &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;OCTQNT + RX_QUANTITY;&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;IF LAST.RECIPIENT_NBR THEN OUTPUT;&lt;/P&gt;&lt;P&gt;LABEL ALLMEDS = 'TOTAL NUMBER OF MEDICATIONS'&lt;/P&gt;&lt;P&gt;TOTALQNT = 'TOTAL QUANTITY OF PILLS'&lt;/P&gt;&lt;P&gt;OCTMEDS = 'TOTAL NUMBER OF MEDICATIONS IN OCTOBER'&lt;/P&gt;&lt;P&gt;OCTQNT = 'TOTAL QUANTITY OF PILLS IN OCTOBER';&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am fairly new to the world of SAS and this is my first attempt at a macro. This is the macro I developed based on some information I found online for macro beginners.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%MACRO&lt;/STRONG&gt; &lt;STRONG&gt;&lt;EM&gt;TOTALMEDS&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;%DO I=&lt;STRONG&gt;1&lt;/STRONG&gt; %TO &lt;STRONG&gt;7&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;DATA = DIABETES.FFYEAR&amp;amp;I (KEEP=RECIPIENT_NBR ALLMEDS TOTALQNT OCTMEDS OCTQNT);&lt;/P&gt;&lt;P&gt;BY RECIPIENT_NBR NDC;&lt;/P&gt;&lt;P&gt;RETAIN ALLMEDS TOTALQNT OCTMEDS OCTQNT;&lt;/P&gt;&lt;P&gt;IF FIRST.RECIPIENT_NBR THEN DO;&lt;/P&gt;&lt;P&gt;ALLMEDS = &lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;TOTALQNT = &lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;OCTMEDS = &lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;OCTQNT = &lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;IF FIRST.NDC THEN DO;&lt;/P&gt;&lt;P&gt;ALLMEDS + &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;TOTALQNT + RX_QUANTITY;&lt;/P&gt;&lt;P&gt;IF MONTH (RX_FILL_DT) = &lt;STRONG&gt;10&lt;/STRONG&gt; THEN DO;&lt;/P&gt;&lt;P&gt;OCTMEDS + &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;OCTQNT + RX_QUANTITY;&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;IF LAST.RECIPIENT_NBR THEN OUTPUT;&lt;/P&gt;&lt;P&gt;LABEL ALLMEDS = 'TOTAL NUMBER OF MEDICATIONS'&lt;/P&gt;&lt;P&gt;TOTALQNT = 'TOTAL QUANTITY OF PILLS'&lt;/P&gt;&lt;P&gt;OCTMEDS = 'TOTAL NUMBER OF MEDICATIONS IN OCTOBER'&lt;/P&gt;&lt;P&gt;OCTQNT = 'TOTAL QUANTITY OF PILLS IN OCTOBER';&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt; TOTALMEDS;&lt;/P&gt;&lt;P&gt;MPRINT (TOTALMEDS): PROC PRINT DATA=DIABETES.FFYEAR&amp;amp;I;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;TOTALMEDS&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So something tells me I got the first statement after the "%Do I=1 …" wrong, and I am not sure where "MPRINT" is supposed to go for SAS to tell me exactly where I am messing up.&amp;nbsp;Is there a more complicated macro I'm supposed to use?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone can please shed some light on this, I would greatly appreciate your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS 9.2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2016 22:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/252856#M268818</guid>
      <dc:creator>TXSASneophyte</dc:creator>
      <dc:date>2016-02-26T22:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I fix my macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/252860#M268819</link>
      <description>Missing the %end; ?</description>
      <pubDate>Fri, 26 Feb 2016 23:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/252860#M268819</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-02-26T23:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I fix my macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/252877#M268820</link>
      <description>&lt;P&gt;If your data goes from 9 to 15 why are you looping from 1 to 7?&lt;/P&gt;
&lt;P&gt;Loop from 9 to 15 and use z2. Format so that the 9 converts to 09.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On top of the solution to add %end.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2016 01:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/252877#M268820</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-27T01:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I fix my macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/252885#M268821</link>
      <description>&lt;P&gt;There shouldn't be an equals sign in a DATA statement. &amp;nbsp;Your original code doesn't use one, but somehow the macro added one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;DATA &lt;STRONG&gt;=&lt;/STRONG&gt; DIABETES.FFYEAR&amp;amp;I (KEEP=RECIPIENT_NBR ALLMEDS TOTALQNT OCTMEDS OCTQNT);&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2016 03:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/252885#M268821</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-02-27T03:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I fix my macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/252914#M268822</link>
      <description>&lt;P&gt;Moreover, the SET statement is missing in your macro. For completeness (and good programming practice), I would also suggest to include a %LOCAL statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, to put everything together, the macro should have the following structure:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro totalmeds;
%local i;
%do i=9 %to 15;
  data diabetes.ffyear%sysfunc(putn(&amp;amp;i,z2.))(keep=recipient_nbr allmeds totalqnt octmeds octqnt);
  set diabetes.ffyear%sysfunc(putn(&amp;amp;i,z2.));
  by ...
  ...
  run;
%end;
%mend totalmeds;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That said, it seems unusual&amp;nbsp;to me that permanent datasets with detail data are overwritten with datasets containing only aggregated data. (I worked on a diabetes project.) But I assume you know what you're doing and the lost information is still available somewhere else.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2016 10:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/252914#M268822</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-27T10:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I fix my macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/254189#M268823</link>
      <description>Thank you so much for the help! Your solution got the macro humming along just nicely &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Despite the name of the library, this is just exploratory temporary data files I'm working with and creating. My computer has very little free memory that storing the datasets in the "work" library would eat up all my free space. Instead, I put everything on an external hard drive, so my "diabetes" folder is just serving as a temporary folder. But I do appreciate your concern! Since you've worked with diabetes data, I may ask you for your lessons-learned in the future!</description>
      <pubDate>Thu, 03 Mar 2016 15:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-my-macro/m-p/254189#M268823</guid>
      <dc:creator>TXSASneophyte</dc:creator>
      <dc:date>2016-03-03T15:12:09Z</dc:date>
    </item>
  </channel>
</rss>

