<?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: What is wrong with my %macro &amp;amp; %do code? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749974#M235804</link>
    <description>&lt;P&gt;Macros must produce legal valid working SAS code after you replace the macro variables with their values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you replace &amp;amp;i with the value of variable &amp;amp;i, then this line&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;outest= PE (rename=(x&amp;amp;i=137));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when &amp;amp;i=1 turns into&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;outest= PE (rename=(x1=137));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is wrong with that? Can you see why this is not valid working SAS code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd offer suggestions about how to fix it, but it's extremely unclear to me what this line is supposed to be doing.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Jun 2021 19:25:07 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-06-23T19:25:07Z</dc:date>
    <item>
      <title>What is wrong with my %macro &amp; %do code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749972#M235803</link>
      <description>&lt;P&gt;I am trying to run a whole bunch of regressions at once, following the code laid out from&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I tried to follow this with my data, and data set, but I have fallen into a problem, and I don't know how to fix it. I'll paste my code below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro DepVar (data=work.import,137);
...
%do i=1 %to &amp;amp;137;  						
		proc reg data=WORK.IMPORT noprint; 	
		outest= PE (rename=(x&amp;amp;i=137));
		model y=x&amp;amp;i; 
	quit;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My dependent variable is titled "DepVar" and there are 137 independent variables in my data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749972#M235803</guid>
      <dc:creator>bmm0628</dc:creator>
      <dc:date>2021-06-23T19:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my %macro &amp; %do code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749974#M235804</link>
      <description>&lt;P&gt;Macros must produce legal valid working SAS code after you replace the macro variables with their values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you replace &amp;amp;i with the value of variable &amp;amp;i, then this line&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;outest= PE (rename=(x&amp;amp;i=137));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when &amp;amp;i=1 turns into&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;outest= PE (rename=(x1=137));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is wrong with that? Can you see why this is not valid working SAS code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd offer suggestions about how to fix it, but it's extremely unclear to me what this line is supposed to be doing.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749974#M235804</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-23T19:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my %macro &amp; %do code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749979#M235807</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Thanks for the response. To be totally honest, I am not sure either. From the article that I was looking at, it says "&lt;SPAN&gt;The OUTEST= option saves the parameter estimates in a data set" so that would be the goal.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749979#M235807</guid>
      <dc:creator>bmm0628</dc:creator>
      <dc:date>2021-06-23T19:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my %macro &amp; %do code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749980#M235808</link>
      <description>&lt;P&gt;The %MACRO statement has mistakes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro DepVar (data=work.import,137);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All parameters that allow passing the values by position (as opposed to by name) have to come FIRST.&amp;nbsp; So you cannot have the named parameter DATA= listed first and the positional one second.&lt;/P&gt;
&lt;P&gt;You cannot start a parameter's name with digit 1.&amp;nbsp; SAS names must start with a letter or an underscore.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SAS code the macro is trying to generate also looks strange.&amp;nbsp; First get your SAS code to work for one dependent variable.&amp;nbsp; Then you can try using a macro to generate that code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you dependent variable is named DEPVAR then it should be to left of the equal sign in the MODEL statement.&amp;nbsp; If you have 137 independent variables why not just put them all into the model to begin with?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;model depvar= indep1 - indep137 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749980#M235808</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-23T19:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my %macro &amp; %do code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749981#M235809</link>
      <description>&lt;P&gt;137 is not a valid SAS name (starts with a digit).&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:33:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749981#M235809</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-23T19:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my %macro &amp; %do code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749982#M235810</link>
      <description>&lt;P&gt;What is the problem with the rename portion? Where does basic SAS syntax fail in the rename part (which is where you macro variable is used)?? I am implying that you must be able to figure out and fix basic SAS syntax errors if you are going to use macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand why you need a rename, or what you are trying to do with the rename, so I cannot suggest an alternative.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Why even use a macro here, when the link you provided gives a non-macro version of the code (and claims it is more efficient)?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749982#M235810</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-23T19:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my %macro &amp; %do code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749983#M235811</link>
      <description>&lt;P&gt;Macro variable names cannot start with a digit: 137 is invalid.&lt;/P&gt;
&lt;P&gt;You should have gotten something like this in your log:&lt;/P&gt;
&lt;PRE&gt;2    %macro DepVar (data=work.import,137);
ERROR: Invalid macro parameter name 137.  It should be a valid SAS identifier no longer than 32
       characters.
ERROR: A dummy macro will be compiled.
3       %put &amp;amp;data &amp;amp;137;
4    %mend;
&lt;/PRE&gt;
&lt;P&gt;So you need a NAME&lt;/P&gt;
&lt;PRE&gt;%macro DepVar (data=work.import, limit=);
&lt;/PRE&gt;
&lt;P&gt;Second, if you are going to define a macro parameter that is not a keyword, like limit=, it &lt;STRONG&gt;must&lt;/STRONG&gt; appear before any of the keyword parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use %do i= 1 %to &amp;amp;limit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third this is just plain wrong.&lt;/P&gt;
&lt;PRE&gt;(rename=(x&amp;amp;i=137));&lt;/PRE&gt;
&lt;P&gt;Data set variable names cannot start with a digit. If you want to use name literals that would have to be "137"n but that requires having option validvarname=any set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have missed the point of the example that used the macro approach.&amp;nbsp; The macro was provided to show a typical macro approach to motivate why it is less efficient than reshaping the data and then using BY processing. Please reread the article.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:44:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749983#M235811</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-23T19:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my %macro &amp; %do code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749993#M235819</link>
      <description>&lt;P&gt;Did no notice where the author says don't do it that way?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;If you use a macro loop to do this computation, it will take a long time for all the reasons stated in the article&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://blogs.sas.com/content/iml/2012/07/18/simulation-in-sas-the-slow-way-or-the-by-way.html" target="_blank"&gt;"The slow way or the BY way."&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;Fortunately, there is a more efficient alternative.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-my-macro-amp-do-code/m-p/749993#M235819</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2021-06-23T20:06:35Z</dc:date>
    </item>
  </channel>
</rss>

