<?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 with by variables for proc sort and regressions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-with-by-variables-for-proc-sort-and-regressions/m-p/496844#M131515</link>
    <description>&lt;P&gt;I am trying to write a macro that runs regressions with or without BY variables. It is working if I specify the BY variables. But what if I dont have any BY variable and want to perform regressions on the whole sample? That is, if the parameter by_var is none, then ignore the BY statement. My code so far is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro regress(input,dep,indep,by_var,cluster_var,FE,modelNo);
	*FE is time fixed effect;
	data sample; set &amp;amp;input.;run;
	ods output ParameterEstimates=para_est fitstatistics=fit;
	proc surveyreg data=sample;
		output out=fitted_&amp;amp;dep&amp;amp;modelNo.(keep=stock date predicted_value rename=(predicted_value=fitted&amp;amp;modelNo._&amp;amp;dep)) p= Predicted_value r=residual u=upper_bound l=lower_bound; 
		cluster &amp;amp;cluster_var;
		by &amp;amp;by_var;
		%if &amp;amp;FE.=1 %then %do;	
			class date;
			model &amp;amp;dep = &amp;amp;indep date/solution; 
		%end;
		%else %if &amp;amp;FE.=0 %then %do;
			model &amp;amp;dep = &amp;amp;indep/solution; 
		%end;
	run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Sep 2018 08:15:27 GMT</pubDate>
    <dc:creator>somebody</dc:creator>
    <dc:date>2018-09-19T08:15:27Z</dc:date>
    <item>
      <title>macro with by variables for proc sort and regressions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-with-by-variables-for-proc-sort-and-regressions/m-p/496844#M131515</link>
      <description>&lt;P&gt;I am trying to write a macro that runs regressions with or without BY variables. It is working if I specify the BY variables. But what if I dont have any BY variable and want to perform regressions on the whole sample? That is, if the parameter by_var is none, then ignore the BY statement. My code so far is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro regress(input,dep,indep,by_var,cluster_var,FE,modelNo);
	*FE is time fixed effect;
	data sample; set &amp;amp;input.;run;
	ods output ParameterEstimates=para_est fitstatistics=fit;
	proc surveyreg data=sample;
		output out=fitted_&amp;amp;dep&amp;amp;modelNo.(keep=stock date predicted_value rename=(predicted_value=fitted&amp;amp;modelNo._&amp;amp;dep)) p= Predicted_value r=residual u=upper_bound l=lower_bound; 
		cluster &amp;amp;cluster_var;
		by &amp;amp;by_var;
		%if &amp;amp;FE.=1 %then %do;	
			class date;
			model &amp;amp;dep = &amp;amp;indep date/solution; 
		%end;
		%else %if &amp;amp;FE.=0 %then %do;
			model &amp;amp;dep = &amp;amp;indep/solution; 
		%end;
	run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Sep 2018 08:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-with-by-variables-for-proc-sort-and-regressions/m-p/496844#M131515</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2018-09-19T08:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: macro with by variables for proc sort and regressions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-with-by-variables-for-proc-sort-and-regressions/m-p/496847#M131516</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make by_var a keyword parameter :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro regress(input,dep, indep, cluster_var, FE, modelNo, by_var=);
	*FE is time fixed effect;
	data sample; set &amp;amp;input.;run;
	ods output ParameterEstimates=para_est fitstatistics=fit;
	proc surveyreg data=sample;
		output out=fitted_&amp;amp;dep&amp;amp;modelNo.(keep=stock date predicted_value rename=(predicted_value=fitted&amp;amp;modelNo._&amp;amp;dep)) p= Predicted_value r=residual u=upper_bound l=lower_bound; 
		cluster &amp;amp;cluster_var;

        %if &amp;amp;by_var. ne %then %do;
            by &amp;amp;by_var;
        %end;

		%if &amp;amp;FE.=1 %then %do;	
			class date;
			model &amp;amp;dep = &amp;amp;indep date/solution; 
		%end;
		%else %if &amp;amp;FE.=0 %then %do;
			model &amp;amp;dep = &amp;amp;indep/solution; 
		%end;
	run;
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note, in the macro signature, how by_var is now after the positional parameters and is followed by "=".&lt;/P&gt;
&lt;P&gt;You can now call the macro with or without giving a value for this parameter :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%regress(input1,dep1, indep1, cluster_var1, 1, model1);
%regress(input1,dep1, indep1, cluster_var1, 1, model1, by_var=var1);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the first call, the by statement will be ignored as the condition "&amp;amp;by_var. ne " will be false.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 08:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-with-by-variables-for-proc-sort-and-regressions/m-p/496847#M131516</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-09-19T08:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: macro with by variables for proc sort and regressions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-with-by-variables-for-proc-sort-and-regressions/m-p/497028#M131601</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/98381"&gt;@somebody&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to write a macro that runs regressions with or without BY variables. It is working if I specify the BY variables. But what if I dont have any BY variable and want to perform regressions on the whole sample? That is, if the parameter by_var is none, then ignore the BY statement. My code so far is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro regress(input,dep,indep,by_var,cluster_var,FE,modelNo);
	*FE is time fixed effect;
	data sample; set &amp;amp;input.;run;
	ods output ParameterEstimates=para_est fitstatistics=fit;
	proc surveyreg data=sample;
		output out=fitted_&amp;amp;dep&amp;amp;modelNo.(keep=stock date predicted_value rename=(predicted_value=fitted&amp;amp;modelNo._&amp;amp;dep)) p= Predicted_value r=residual u=upper_bound l=lower_bound; 
		cluster &amp;amp;cluster_var;
		by &amp;amp;by_var;
		%if &amp;amp;FE.=1 %then %do;	
			class date;
			model &amp;amp;dep = &amp;amp;indep date/solution; 
		%end;
		%else %if &amp;amp;FE.=0 %then %do;
			model &amp;amp;dep = &amp;amp;indep/solution; 
		%end;
	run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please also check the documentation for SURVEYREG (and the other survey analysis procedures) and the by statement.&lt;/P&gt;
&lt;P&gt;From the online documentation:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Note that using a BY statement provides completely separate analyses of the BY groups. It does not provide a statistically valid domain (subpopulation) analysis, where the total number of units in the subpopulation is not known with certainty. You should use the DOMAIN statement to obtain domain analysis.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Be very sure that you actually want BY instead of DOMAIN.&lt;/P&gt;
&lt;P&gt;There is more detail in the DOMAIN statement documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 15:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-with-by-variables-for-proc-sort-and-regressions/m-p/497028#M131601</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-19T15:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: macro with by variables for proc sort and regressions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-with-by-variables-for-proc-sort-and-regressions/m-p/500276#M133208</link>
      <description>&lt;P&gt;Say for example, I want to study the effect of food on health in different countries.&amp;nbsp;Should I would use PROC SURVEYREG with the BY or DOMAIN statement on Country?Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 07:06:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-with-by-variables-for-proc-sort-and-regressions/m-p/500276#M133208</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2018-10-01T07:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: macro with by variables for proc sort and regressions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-with-by-variables-for-proc-sort-and-regressions/m-p/508082#M136401</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I understand that the following checks if by_var exist.&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%if&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;by_var&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%then&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;by_var&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token macrostatement"&gt;%end&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;What if I want to check if by_var does not exist? I tried&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%if&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;by_var&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;e&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%then&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;; something;&lt;/SPAN&gt;&lt;SPAN class="token macrostatement"&gt;%end&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but it does not work&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Oct 2018 07:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-with-by-variables-for-proc-sort-and-regressions/m-p/508082#M136401</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2018-10-28T07:01:22Z</dc:date>
    </item>
  </channel>
</rss>

