<?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 SAS Macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330573#M74195</link>
    <description>Thanks so much for your help. I really appreciate it very much!</description>
    <pubDate>Tue, 07 Feb 2017 18:46:59 GMT</pubDate>
    <dc:creator>buechler66</dc:creator>
    <dc:date>2017-02-07T18:46:59Z</dc:date>
    <item>
      <title>Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330520#M74170</link>
      <description>&lt;P&gt;I have the following program and I'd like to try to use macros to simplify the repetative code. As you can see it runs the same steps for similarly named and structured datasets. The only difference is Quarter (Quarter 171 and Quarter 164). &amp;nbsp;The datasets are read in and then merged.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would there be a nice way to use macros to read in any number of Quarter specific datasets, say 163, 164, and 171, without having to hardcode the Quarter throughout?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Permanent storage location of quarterly summary datasets*/
libname DSs 'K:\TTMS\IV_Internal SPM\Parallel Testing\Parallel Test Harness\PTH_Quarterly_DSs';

data querydatasummary171;
set DSs.querydatasummary171;
if imb_dlvry_zip_5='171';
rename total=total_171 percent=percent_171;
drop rule_order score_impacting imb_dlvry_zip_5;
run;

/*Sort for merge*/
proc sort;
by rule_nm;
run;

data querydatasummary164;
set DSs.querydatasummary164;
if imb_dlvry_zip_5='164';
rename total=total_164 percent=percent_164;
drop rule_order score_impacting imb_dlvry_zip_5;
run;

/*Sort for merge*/
proc sort;
by rule_nm;
run;

/*Merge the datasets for comparison*/
data combined;
merge querydatasummary171 querydatasummary164;
by rule_nm;
run;

/*Reorder columns*/
data Quarterly_Summary_Comparisons;
retain rule_nm total_164 total_171 percent_164 percent_171;
set combined;
format total_164 comma12.0 total_171 comma12.0;
run;

/*For appearance*/
proc sort;
by descending total_171;
run;

/*Print report*/
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 16:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330520#M74170</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2017-02-07T16:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330530#M74174</link>
      <description>&lt;P&gt;Check next macro and execution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro prep_qtr(&lt;STRONG&gt;qtr&lt;/STRONG&gt;);
   data querydatasummary&lt;STRONG&gt;&amp;amp;qtr.&lt;/STRONG&gt;;
     set DSs.querydatasummary&lt;STRONG&gt;&amp;amp;qtr.&lt;/STRONG&gt;;
           if imb_dlvry_zip_5=&lt;STRONG&gt;"&amp;amp;qtr"&lt;/STRONG&gt;;
           rename total=total_&lt;STRONG&gt;&amp;amp;qtr.&lt;/STRONG&gt;  percent=percent_&lt;STRONG&gt;&amp;amp;qtr.&lt;/STRONG&gt;;
          drop rule_order score_impacting imb_dlvry_zip_5;
   run;

   /*Sort for merge*/
   proc sort;
      by rule_nm;
   run;
%mend prep_qtr;
%prep_qtr(171);
%prep_qtr(164);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330530#M74174</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-07T17:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330540#M74180</link>
      <description>&lt;P&gt;Here's a suggestion: provide some example data and what the result (the proc print)&amp;nbsp;should look like.&lt;/P&gt;
&lt;P&gt;I suspect the final result, proc print like output or very similar could be accomplished with one datastep and a report procedure. And would be extensible to more than two data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And considering that your data sets have names like querydatasummary171, might even be possible without creating those individual summaries.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330540#M74180</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-07T17:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330546#M74185</link>
      <description>&lt;P&gt;I'm suspecting something similar ... since the variable names are TOTAL, I'm suspecting there is just one observation per combination of rul_nm and zip_5.&amp;nbsp; If that's the case, here's a sample program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc tabulate data=have;&lt;/P&gt;
&lt;P&gt;where imb_dlvry_zip_5 in ('164', '171');&lt;/P&gt;
&lt;P&gt;class imb_dlvry_zip_5 rule_nm;&lt;/P&gt;
&lt;P&gt;var total percent;&lt;/P&gt;
&lt;P&gt;tables rule_nm, sum=' ' * imb_dlvry_zip_5 * (total percent);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there are actually multiple observations per rule_nm / zip_5, you may need to switch over to proc report instead of proc tabulate.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330546#M74185</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-07T17:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330547#M74186</link>
      <description>&lt;P&gt;Awesome! &amp;nbsp;Thanks so much! &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyway to simplify the Merge Statement as well using this macro logic? &amp;nbsp;The problem is that there might be two Quarters (171, 164) or three Quarters (171, 164, 163), or even more quarters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I stuck having to hard code the Merge Statement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data combined;
merge querydatasummary171 querydatasummary164;
by rule_nm;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330547#M74186</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2017-02-07T17:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330549#M74188</link>
      <description>Does this assume I've simply Appended the individual datasets together?</description>
      <pubDate>Tue, 07 Feb 2017 17:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330549#M74188</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2017-02-07T17:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330553#M74189</link>
      <description>&lt;P&gt;Yes, in this case, you might have to begin with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;set DSs&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;querydatasummary171 DSs&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;querydatasummary164;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It further assumes that each summary data set contains only data for that particular imb_dlvry_zip_5.&amp;nbsp; If there are mixes and matches (for example, if DSs&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;querydatasummary164 could contain observations where imb_dlvry_zip_5 is actually "171"), there will be problems with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be possible to modify the process that creates the individual querydatasummary data sets, so you get all the data in one place.&amp;nbsp; I don't know if you have control over that.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:40:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330553#M74189</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-07T17:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330556#M74190</link>
      <description>&lt;P&gt;Your suggestion is genius. &amp;nbsp;Thanks so much. I've attached the sample output using the Proc Tabulate as you suggested. &amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My only remaining issues would be how to do the following (if possible):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Order the resulting table by by Total, so that the largest Total appears at the top of the chart?&lt;/P&gt;&lt;P&gt;2. Format the Total column so that it has Commas, and so it does not have the trailing decimal values&lt;/P&gt;&lt;P&gt;3. Format the Percent column so that is displays as a true percentage (e.g. Volume Matching&amp;nbsp;at the bottom of the attached output should display as 94.01% and 91.07% respectively)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13411i4FA9C42F2AA3DFBC/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Capture.JPG" title="Capture.JPG" /&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330556#M74190</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2017-02-07T17:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330560#M74191</link>
      <description>&lt;P&gt;I'm doing something wrong trying to get my formats included:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=combined;
class imb_dlvry_zip_5 rule_nm;
var total percent;
tables rule_nm, sum=' ' * imb_dlvry_zip_5 * (total percent);
format total=comma12.0 percent=percent8.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MPRINT(LOOPY):   proc tabulate data=combined;
NOTE: Line generated by the invoked macro "LOOPY".
5      class imb_dlvry_zip_5 rule_nm; var total percent; tables rule_nm, sum=' ' * imb_dlvry_zip_5 * (total percent); format
5   ! total=comma12.0 percent=percent8.2; run;
           -
           22
           200
MPRINT(LOOPY):   class imb_dlvry_zip_5 rule_nm;
MPRINT(LOOPY):   var total percent;
MPRINT(LOOPY):   tables rule_nm, sum=' ' * imb_dlvry_zip_5 * (total percent);
MPRINT(LOOPY):   format total=comma12.0 percent=percent8.2 run;

ERROR 22-322: Syntax error, expecting one of the following: a name, a format name, ;, -, :, _ALL_, _CHARACTER_, _CHAR_,
              _NUMERIC_.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE TABULATE used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              608.70k
      OS Memory           14728.00k
      Timestamp           02/07/2017 01:10:43 PM&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2017 18:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330560#M74191</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2017-02-07T18:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330563#M74192</link>
      <description>&lt;P&gt;You're moving in the right direction, but the syntax needs to be tweaked a little.&amp;nbsp; TABULATE uses *f= to apply a format.&amp;nbsp; Untested, but this would be my first attempt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc tabulate data=have;&lt;/P&gt;
&lt;P&gt;where imb_dlvry_zip_5 in ('164', '171');&lt;/P&gt;
&lt;P&gt;class imb_dlvry_zip_5 rule_nm;&lt;/P&gt;
&lt;P&gt;var total percent;&lt;/P&gt;
&lt;P&gt;tables rule_nm, sum=' ' * imb_dlvry_zip_5 * (total*f=comma10.0 percent*f=percent8.1);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC TABULATE does support a few values for ORDER=, but I'm not sure they would help.&amp;nbsp; After all, it's entirely possible that "164" would have a different maximum value than "171".&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 18:22:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330563#M74192</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-07T18:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330564#M74193</link>
      <description>&lt;P&gt;If your data is summarized then you could use&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by descending total;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;Proc tabulate data= have order=data;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you have multiple columns with the variable "total", such as for each level of the imb_dlvry_sip_5, then the left most column may not have the expected order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2 and 3 can be accomplished with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;tables&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; rule_nm, imb_dlvry_zip_5 * (total*sum=&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;' '&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; *&lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;f&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;=&lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;comma12.&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; percent*sum=&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;' '&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; *&lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;f&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;=&lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;percent9.2&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 18:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330564#M74193</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-07T18:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330572#M74194</link>
      <description>Thanks again so much. I appreciate you taking the time to help.</description>
      <pubDate>Tue, 07 Feb 2017 18:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330572#M74194</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2017-02-07T18:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330573#M74195</link>
      <description>Thanks so much for your help. I really appreciate it very much!</description>
      <pubDate>Tue, 07 Feb 2017 18:46:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-Macros/m-p/330573#M74195</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2017-02-07T18:46:59Z</dc:date>
    </item>
  </channel>
</rss>

