<?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 macros in reports in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783062#M249643</link>
    <description>&lt;P&gt;Why not just do them all at once?&lt;/P&gt;
&lt;P&gt;The beginning of your code is doing that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final_drugbug;
  set drugbug_combined;
  if ns_n='.' then delete;
  if ns_n =0 then delete;
  if it_n='.' then it_n=isolates_hospital_n;
run;

proc sort data= final_drugbug;
  by drug_bug;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So just have the rest of the code also use BY grouping.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc univariate data=final_drugbug;
  by drug_bug;
  var ps_n;
  histogram;
  output out=means mean=ps_mean std=ps_std; 
run;

data Ami_abQC;
  merge final_drugbug means;
  by drug_bug;
run;

proc print data=Ami_abQC;
  by drug_bug;
  sum it_n ps_n ns_n;
  var hospital drug bug isolates_hospital_n it_n ps_n ns_n;
run;

proc print data=Ami_abQC noobs;
  where abs(ps_n-ps_mean) &amp;gt; 2*ps_std ;
  by drug_bug;
  var hospital drug bug isolates_hospital_n it_n ps_n ns_n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 30 Nov 2021 05:13:25 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-11-30T05:13:25Z</dc:date>
    <item>
      <title>Using macros in reports</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783048#M249635</link>
      <description>&lt;P&gt;I'm preparing a report that shows % susceptibilities for different drug-bugs combinations, histogram, IQR for % susceptibles, number of hospitals, number of isolates (ns_n) and number of susceptibles (ps_n)&amp;nbsp; and I'm using the following:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data= drugbug_combined out=drugbug;&lt;BR /&gt;by drug_bug;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data 2018_drugbug;&lt;BR /&gt;set drugbug;&lt;BR /&gt;if ns_n='.' then delete;&lt;BR /&gt;if ns_n =0 then delete;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data final_drugbug;&lt;BR /&gt;set 2018_drugbug;&lt;BR /&gt;if it_n='.' then do;&lt;BR /&gt;it_n=isolates_hospital_n;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;proc univariate data=final_drugbug;&lt;BR /&gt;by drug_bug;&lt;BR /&gt;var ps_n;&lt;BR /&gt;where drug_bug='Drug1 bug 1';&lt;BR /&gt;histogram;&lt;BR /&gt;run;&lt;BR /&gt;data Ami_ab;&lt;BR /&gt;set final_drugbug;&lt;BR /&gt;where drug_bug='Drug1 bug 1';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql noprint;;&lt;BR /&gt;select mean (ps_n) into: mean from Ami_ab;&lt;BR /&gt;select std (ps_n) into : std from Ami_ab;&lt;BR /&gt;quit;&lt;BR /&gt;data Ami_abQC;&lt;BR /&gt;set Ami_ab;&lt;BR /&gt;where drug_bug='Drug 1 bug 1' AND&lt;BR /&gt;ps_n&amp;lt; &amp;amp;mean-2*&amp;amp;std OR ps_n &amp;gt; &amp;amp;mean+2*&amp;amp;std;&lt;BR /&gt;proc print noobs;&lt;BR /&gt;var hospital drug_bug drug bug isolates_hospital_n it_n ps_n ns_n;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=Ami_ab;&lt;BR /&gt;sum it_n ps_n ns_n;&lt;BR /&gt;var hospital drug_bug drug bug isolates_hospital_n it_n ps_n ns_n;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use a macro since I have more than 25 different drug bug combinations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 23:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783048#M249635</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2021-11-29T23:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros in reports</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783058#M249640</link>
      <description>&lt;P&gt;What specifically do you need help with?&lt;/P&gt;
&lt;P&gt;What parts are changing from each iteration? The first link below is a tutorial that walks you through converting a working program to a macro program with an automatic call for all possible values in one variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Tutorial on converting a working program to a macro&lt;/STRONG&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/47035"&gt;@mayasak&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm preparing a report that shows % susceptibilities for different drug-bugs combinations, histogram, IQR for % susceptibles, number of hospitals, number of isolates (ns_n) and number of susceptibles (ps_n)&amp;nbsp; and I'm using the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data= drugbug_combined out=drugbug;&lt;BR /&gt;by drug_bug;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data 2018_drugbug;&lt;BR /&gt;set drugbug;&lt;BR /&gt;if ns_n='.' then delete;&lt;BR /&gt;if ns_n =0 then delete;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data final_drugbug;&lt;BR /&gt;set 2018_drugbug;&lt;BR /&gt;if it_n='.' then do;&lt;BR /&gt;it_n=isolates_hospital_n;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;proc univariate data=final_drugbug;&lt;BR /&gt;by drug_bug;&lt;BR /&gt;var ps_n;&lt;BR /&gt;where drug_bug='Drug1 bug 1';&lt;BR /&gt;histogram;&lt;BR /&gt;run;&lt;BR /&gt;data Ami_ab;&lt;BR /&gt;set final_drugbug;&lt;BR /&gt;where drug_bug='Drug1 bug 1';&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql noprint;;&lt;BR /&gt;select mean (ps_n) into: mean from Ami_ab;&lt;BR /&gt;select std (ps_n) into : std from Ami_ab;&lt;BR /&gt;quit;&lt;BR /&gt;data Ami_abQC;&lt;BR /&gt;set Ami_ab;&lt;BR /&gt;where drug_bug='Drug 1 bug 1' AND&lt;BR /&gt;ps_n&amp;lt; &amp;amp;mean-2*&amp;amp;std OR ps_n &amp;gt; &amp;amp;mean+2*&amp;amp;std;&lt;BR /&gt;proc print noobs;&lt;BR /&gt;var hospital drug_bug drug bug isolates_hospital_n it_n ps_n ns_n;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc print data=Ami_ab;&lt;BR /&gt;sum it_n ps_n ns_n;&lt;BR /&gt;var hospital drug_bug drug bug isolates_hospital_n it_n ps_n ns_n;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to use a macro since I have more than 25 different drug bug combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 02:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783058#M249640</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-30T02:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros in reports</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783061#M249642</link>
      <description>&lt;P&gt;Thank you, the drug_bug variable is the one changing from each iteration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 03:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783061#M249642</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2021-11-30T03:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros in reports</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783062#M249643</link>
      <description>&lt;P&gt;Why not just do them all at once?&lt;/P&gt;
&lt;P&gt;The beginning of your code is doing that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final_drugbug;
  set drugbug_combined;
  if ns_n='.' then delete;
  if ns_n =0 then delete;
  if it_n='.' then it_n=isolates_hospital_n;
run;

proc sort data= final_drugbug;
  by drug_bug;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So just have the rest of the code also use BY grouping.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc univariate data=final_drugbug;
  by drug_bug;
  var ps_n;
  histogram;
  output out=means mean=ps_mean std=ps_std; 
run;

data Ami_abQC;
  merge final_drugbug means;
  by drug_bug;
run;

proc print data=Ami_abQC;
  by drug_bug;
  sum it_n ps_n ns_n;
  var hospital drug bug isolates_hospital_n it_n ps_n ns_n;
run;

proc print data=Ami_abQC noobs;
  where abs(ps_n-ps_mean) &amp;gt; 2*ps_std ;
  by drug_bug;
  var hospital drug bug isolates_hospital_n it_n ps_n ns_n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Nov 2021 05:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783062#M249643</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-30T05:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros in reports</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783256#M249707</link>
      <description>&lt;P&gt;Thank you Tom. It worked but I have a question. Is there a way that we get aggregated, hospital numbers, ps_n (percent susceptibility) and # of isolates (ns_n)&amp;nbsp; data for each drug-bug combinations as in the table below?.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mayasak_0-1638289563216.png" style="width: 465px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66278i876368329A1A0E44/image-dimensions/465x208?v=v2" width="465" height="208" role="button" title="mayasak_0-1638289563216.png" alt="mayasak_0-1638289563216.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mayasak_1-1638289782802.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66279i1892A6A6E840C5AC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mayasak_1-1638289782802.png" alt="mayasak_1-1638289782802.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 19:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783256#M249707</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2021-11-30T19:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros in reports</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783276#M249715</link>
      <description>&lt;P&gt;I am very skeptical that you need macros here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This seems to be the key piece of code here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where drug_bug='Drug 1 bug 1' AND
ps_n&amp;lt; &amp;amp;mean-2*&amp;amp;std OR ps_n &amp;gt; &amp;amp;mean+2*&amp;amp;std;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you are searching for records where the value of ps_n is ±2 standard deviations or more from the mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you can do is use &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/statug/statug_stdize_toc.htm" target="_self"&gt;PROC STDIZE&lt;/A&gt; to get this information. Using a BY statement in PROC STDIZE, you can have all 25 possible drug bug combinations calculated at once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example on something that looks like your data, but probably won't actually work on your data without modification.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc stdize data=whatever oprefix=o_ sprefix=s_ out=want;
by drug_bug;
var ps_n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Nov 2021 21:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macros-in-reports/m-p/783276#M249715</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-30T21:06:41Z</dc:date>
    </item>
  </channel>
</rss>

