<?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: SAS macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610702#M177890</link>
    <description>&lt;P&gt;Really sorry for back-to-back questions;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I copy/past the whole macro in my SAS editor, then call it as follows;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%itsa(model=sitsa, dataset=Counterfactual, outcome=percent_intervention, time=month, interrupt=74, lag=12);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then what needs to be done to get the output?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;S&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Dec 2019 12:50:57 GMT</pubDate>
    <dc:creator>sks521</dc:creator>
    <dc:date>2019-12-10T12:50:57Z</dc:date>
    <item>
      <title>SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610664#M177866</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to&amp;nbsp;make a&amp;nbsp;&lt;SPAN&gt;macro code available to call within the SAS environment and execute it. can someone share examples or explain how to do it please?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;S&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 11:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610664#M177866</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-12-10T11:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610667#M177867</link>
      <description>&lt;P&gt;Store it in a place where people can read it with %include.&lt;/P&gt;
&lt;P&gt;Or put it in your &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n1o5fkxq0gqdpcn1xs3ksdks69tf.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;autocall&lt;/A&gt; library.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 11:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610667#M177867</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-10T11:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610677#M177872</link>
      <description>&lt;P&gt;Thanks for your response but can you be more specific. It's a macro someone else has written and made available online. My first question is how and where do I store it and how can I invoke it within my SAS programme and execute.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 11:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610677#M177872</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-12-10T11:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610679#M177873</link>
      <description>&lt;P&gt;You can simply copy/paste it into your program editor and execute the code, then it is compiled.&lt;/P&gt;
&lt;P&gt;Or you store it in a place where your SAS session can read it and use &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsglobal&amp;amp;docsetTarget=p1s3uhhqtscz2sn1otiatbovfn1t.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;%include&lt;/A&gt; in your code.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 11:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610679#M177873</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-10T11:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610680#M177874</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to copy/paste and run it in my SAS programme but it doesn't give me any output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example the macro is;&lt;/P&gt;&lt;P&gt;%macro itsa(model=, dataset=, outcome=, time=, interrupt=, lag=);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So on and so forth......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the following to invoke it within the programme;&lt;/P&gt;&lt;P&gt;%INCLUDE "I:\CHCBradford\Syntax\ITSA.sas" ;&lt;BR /&gt;option mprint;&lt;BR /&gt;%macro itsa(model=sitsa, dataset=ITS_ACE, outcome=percent_intervention, time=month, interrupt=74, lag=12);&lt;BR /&gt;%test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how do I use it for my data set, I mean where do I say which data set to look into for the above parameters?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 11:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610680#M177874</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-12-10T11:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610687#M177879</link>
      <description>&lt;P&gt;I STRONGLY suggest that you familiarize yourself with the syntax of at least the basic macro statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro itsa(model=sitsa, dataset=ITS_ACE, outcome=percent_intervention, time=month, interrupt=74, lag=12);
/* this is not a macro CALL, it is the start of a definition, and will do NOTHING in itself */
%test;
/* this is the call of macro test, which must have been defined somewhere with %macro test; ..... %mend; */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How you have to call this externally supplied macro needs to be taken from the documentation for that macro.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 12:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610687#M177879</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-10T12:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610692#M177882</link>
      <description>&lt;P&gt;Thanks Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am copying the macro in SAS code window below. I used this syntax to CALL it;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro itsa(model=, dataset=, outcome=, time=, interrupt=, lag=);

%if (&amp;amp;model=sitsa) %then %do;

    * Create SITSA dummy variables;

    data sitsa_vars;

         set &amp;amp;dataset;

         t=_n_;

         if &amp;amp;time&amp;lt;&amp;amp;interrupt then x=0;

         else x=1;

         if &amp;amp;time&amp;lt;&amp;amp;interrupt then tx=0;

         else tx+1;

         keep &amp;amp;time &amp;amp;outcome t x tx;

    run;
	 * Compute lag+1 for proc model;

    %let lagl=%eval(&amp;amp;lag + 1);

    * If lag is set to 0 or missing then conduct SITSA with OLS regression;

    * If lag&amp;gt;0 then conduct SITSA with OLS regression + Newey-West standard errors;

    %if (&amp;amp;lag&amp;lt;1) %then %do;

         ods output ParameterEstimates=sitsa_stat TestResults=sitsa_stat2 CovB=sitsa_covar;

         proc model data=sitsa_vars;

              parms b0 b1 b2 b3;

              &amp;amp;outcome = b0+(b1*t)+(b2*x)+(b3*tx);

              fit &amp;amp;outcome / covb;

              test b1+b3;

         run; quit;
		  %end;

    %else %do;

         ods output ParameterEstimates=sitsa_stat TestResults=sitsa_stat2 CovB=sitsa_covar;

         proc model data=sitsa_vars;

              parms b0 b1 b2 b3;

              &amp;amp;outcome = b0+(b1*t)+(b2*x)+(b3*tx);

              fit &amp;amp;outcome / covb gmm kernel=(bart,&amp;amp;lagl,0) vardef=n;

              test b1+b3;

         run; quit;

    %end;
	   * Produce tables for model coefficients;

    data sitsa_stat;

         set sitsa_stat;

         keep parameter estimate stderr probt;

         rename probt=prob;

    run;

    data sitsa_stat2;

         set sitsa_stat2;

         keep label probchisq;

         rename label=parameter probchisq=prob;

    run;
	    * Append stats from outputs;

    data sitsa_stat;

         set sitsa_stat sitsa_stat2;

    run;
	* Calculate and save sum of b1+b3 coefficients;

    proc means data=sitsa_stat(where=(parameter='b1' or parameter='b3')) sum noprint;

         output out=b1b3_est sum= / autoname;

         var estimate;

    run;

    * Save sum to macro variable;

    data _null_;

         set b1b3_est;

         call symputx("Sum", Estimate_Sum);

    run;

   * Add sum as b1+b3 parameter estimate;

    data sitsa_stat;

         set sitsa_stat;

         if parameter='b1+b3' then estimate=&amp;amp;Sum;

    run;

  * Save covariance to macro variable;

    data _null_;

         set sitsa_covar;

         if parameter='b3' then call symputx("Covar", b1);

    run;

    

    * Save b1 and b3 standard errors as macro variables;

    data _null_;

         set sitsa_stat;

         if parameter='b1' then call symputx("SE_1", StdErr);

         if parameter='b3' then call symputx("SE_3", StdErr);

    run;

 * Calculate b1+b3 standard error;

    %let sum_se=%sysfunc(sqrt(&amp;amp;SE_1.**2+&amp;amp;SE_3.**2+2*&amp;amp;Covar.));

    * Add b1+b3 standard error;

    * Calculate 95% confidence intervals for all results;

    data sitsa_stat;

         set sitsa_stat;

         if parameter='b1+b3' then StdErr=&amp;amp;sum_se;

         CI_LL=(estimate-1.96*StdErr);

         CI_UL=(estimate+1.96*StdErr);

    run;
	  * Calculate residual/predicted values;

    data _null_;

         set sitsa_stat;

         if parameter='b0' then call symputx("b0", Estimate);

         if parameter='b1' then call symputx("b1", Estimate);

         if parameter='b2' then call symputx("b2", Estimate);

         if parameter='b3' then call symputx("b3", Estimate);

    run;

    data sitsa_vars;

         set sitsa_vars;

         pred=&amp;amp;b0+(&amp;amp;b1*t)+(&amp;amp;b2*x)+(&amp;amp;b3*tx);

        res=(&amp;amp;outcome-pred);
		run;
		 * Print coefficient estimates;

    proc print data=sitsa_stat;

         id parameter;

    run;



    * Define plot characteristics;

    symbol1 color=black line=1 interpol=join value=star;

    symbol2 color=black line=1 interpol=join value=dot;                                                                                                    

    axis1 label=('Time') offset=(1,1);

    axis2 label=('Outcome') offset=(0,0);

    legend1 label=('Phase:') value=('Pre-Interruption' 'Post-Interruption');

    pattern1 color=gray;

    pattern2 color=black;

* Produce 2x plots;

    proc gplot data=sitsa_vars;                                                                                                                

        plot &amp;amp;outcome*t = x / haxis=axis1 vaxis=axis2 cvref=black legend=legend1;

    run; quit;

    proc gplot data=sitsa_vars;                                                                                                                

        plot &amp;amp;outcome*t = x / areas=2 haxis=axis1 vaxis=axis2 cvref=black legend=legend1;

    run; quit;
	 * Delete additional datasets;

    proc datasets library=work noprint;

        delete sitsa_stat sitsa_stat2 b1b3_est sitsa_covar;

    run; quit;



%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; %INCLUDE itsa;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I execute it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are right, I am not familiar with macro language but using this macro is the best way of analysing the data I have, so I am trying to utilise given resources as best as I can.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for all your help.&lt;/P&gt;&lt;P&gt;S&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 12:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610692#M177882</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-12-10T12:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610696#M177886</link>
      <description>&lt;P&gt;You &lt;EM&gt;call&lt;/EM&gt; the macro with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%itsa(model=X1, dataset=X2, outcome=X3, time=X4, interrupt=X5, lag=X6);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where X* are just placeholders for the values &lt;EM&gt;you&lt;/EM&gt; need to supply, according to the documentation.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 12:36:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610696#M177886</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-10T12:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610702#M177890</link>
      <description>&lt;P&gt;Really sorry for back-to-back questions;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I copy/past the whole macro in my SAS editor, then call it as follows;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%itsa(model=sitsa, dataset=Counterfactual, outcome=percent_intervention, time=month, interrupt=74, lag=12);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then what needs to be done to get the output?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;S&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 12:50:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610702#M177890</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-12-10T12:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610709#M177893</link>
      <description>&lt;P&gt;Look what the log says. If that does not provide a clue (no WARNING/ERROR either from running the macro definition nor from the call), get in touch with the author.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 12:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610709#M177893</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-10T12:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610716#M177897</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277970"&gt;@sks521&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Really sorry for back-to-back questions;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, I copy/past the whole macro in my SAS editor, then call it as follows;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%itsa(model=sitsa, dataset=Counterfactual, outcome=percent_intervention, time=month, interrupt=74, lag=12);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then what needs to be done to get the output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You might have to use the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods html;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before you run the macro to make the graphics appear (although for most people ODS HTML is on by default).&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 13:13:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610716#M177897</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-10T13:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610737#M177907</link>
      <description>&lt;P&gt;Thanks it solved the problem.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 14:32:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610737#M177907</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-12-10T14:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610763#M177919</link>
      <description>&lt;P&gt;&lt;STRONG&gt;UCLA introductory tutorial on macro variables and macros&lt;/STRONG&gt;&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;&amp;nbsp;&lt;/P&gt;
&lt;P&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;/P&gt;
&lt;P&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;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Examples of common macro usage&lt;/STRONG&gt;&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;</description>
      <pubDate>Tue, 10 Dec 2019 16:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro/m-p/610763#M177919</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-12-10T16:17:11Z</dc:date>
    </item>
  </channel>
</rss>

