<?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: %MACRO and PROC MEANS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545299#M150827</link>
    <description>&lt;P&gt;I understand this is a learning exercise, but I hope you also realize that there's no need for macros in this situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC MEANS DATA=SasHelp.PriceData NOPRINT;
    VAR price1-price17;
    OUTPUT OUT=work.medians median=med_1-med_17 cv=cv_1-cv_17;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 22 Mar 2019 16:53:43 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-03-22T16:53:43Z</dc:date>
    <item>
      <title>%MACRO and PROC MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545283#M150819</link>
      <description>&lt;P&gt;I am trying to learn the SAS %MACRO procedure but something is not working correctly. I am using the&amp;nbsp;SasHelp.PriceData data set and am trying to write some simply code to calculate the median and coefficient of variation for each price feature (preice1-price17). I am running the below code. When I invoke my %DO_Median macro I expect there to be 17 Median_&amp;amp;I table, however the macro does not seem to be generating any output as currently written. What am i missing or not understanding about the %MACRO syntax?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO DO_MEDIAN;
%DO I=1 %TO I=17;

	PROC MEANS DATA=SasHelp.PriceData NOPRINT;
		VAR price&amp;amp;I;
		OUTPUT OUT=work.Medians_&amp;amp;I  Median=Med_&amp;amp;I CV=CV_&amp;amp;I;
	RUN;

%END;
%MEND DO_MEDIAN;

%DO_MEDIAN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2019 16:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545283#M150819</guid>
      <dc:creator>tgrandchamp</dc:creator>
      <dc:date>2019-03-22T16:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: %MACRO and PROC MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545287#M150821</link>
      <description>&lt;P&gt;The first thing you have to understand is, that the macro language is nothing more, but a code-generator or text-replacing-system. You start writing macros, when you have code that you want/have to execute multiple times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And please don't not write all code in upcase, it makes reading unnecessary difficult.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace the line&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%DO&lt;/SPAN&gt; I&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%TO&lt;/SPAN&gt; I&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;17&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;with&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%DO&lt;/SPAN&gt; I&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%TO&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;17&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2019 16:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545287#M150821</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-22T16:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: %MACRO and PROC MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545289#M150823</link>
      <description>&lt;P&gt;Remember to check your log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can add the following code to your macros to help with debugging:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen;
options mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I find the MLOGIC can add to much so I don't always use that, but you should be aware it exists when working with macros.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185697"&gt;@tgrandchamp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to learn the SAS %MACRO procedure but something is not working correctly. I am using the&amp;nbsp;SasHelp.PriceData data set and am trying to write some simply code to calculate the median and coefficient of variation for each price feature (preice1-price17). I am running the below code. When I invoke my %DO_Median macro I expect there to be 17 Median_&amp;amp;I table, however the macro does not seem to be generating any output as currently written. What am i missing or not understanding about the %MACRO syntax?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO DO_MEDIAN;
%DO I=1 %TO I=17;

	PROC MEANS DATA=SasHelp.PriceData NOPRINT;
		VAR price&amp;amp;I;
		OUTPUT OUT=work.Medians_&amp;amp;I  Median=Med_&amp;amp;I CV=CV_&amp;amp;I;
	RUN;

%END;
%MEND DO_MEDIAN;

%DO_MEDIAN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 16:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545289#M150823</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-03-22T16:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: %MACRO and PROC MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545299#M150827</link>
      <description>&lt;P&gt;I understand this is a learning exercise, but I hope you also realize that there's no need for macros in this situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC MEANS DATA=SasHelp.PriceData NOPRINT;
    VAR price1-price17;
    OUTPUT OUT=work.medians median=med_1-med_17 cv=cv_1-cv_17;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2019 16:53:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545299#M150827</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-03-22T16:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: %MACRO and PROC MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545305#M150831</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185697"&gt;@tgrandchamp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to learn the SAS %MACRO procedure but something is not working correctly. I am using the&amp;nbsp;SasHelp.PriceData data set and am trying to write some simply code to calculate the median and coefficient of variation for each price feature (preice1-price17). I am running the below code. When I invoke my %DO_Median macro I expect there to be 17 Median_&amp;amp;I table, however the macro does not seem to be generating any output as currently written. What am i missing or not understanding about the %MACRO syntax?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO DO_MEDIAN;
%DO I=1 %TO I=17;

	PROC MEANS DATA=SasHelp.PriceData NOPRINT;
		VAR price&amp;amp;I;
		OUTPUT OUT=work.Medians_&amp;amp;I  Median=Med_&amp;amp;I CV=CV_&amp;amp;I;
	RUN;

%END;
%MEND DO_MEDIAN;

%DO_MEDIAN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;An aside on the way you are creating your output variable names. Prefixing related values with the statistic &lt;STRONG&gt;may &lt;/STRONG&gt;depending on how you use&amp;nbsp; the resulting data make it harder to reference values. If you want to select all of the similar price1 variables it may be more cumbersome. MAY.&lt;/P&gt;
&lt;P&gt;SAS does provide a way to append the statistic as suffix to the variable name. Coupled with that plus the variable list you perhaps could do something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc means data=sashelp.pricedata noprint;
   var price: ;
   output out=work.medians median= cv= /autoname;
run;&lt;/PRE&gt;
&lt;P&gt;Calculating all of the values in one pass.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then if you only want to use the values for Price8 later select using Keep= Price8_: ;&lt;/P&gt;
&lt;P&gt;The : attached to part of variable name selects all variables that start with that text. So the VAR statement in proc means above is asking to summarize all variables whose names start with PRICE.&lt;/P&gt;
&lt;P&gt;If I thought I really needed the variables to start with the statistic , then I might do something like:&lt;/P&gt;
&lt;PRE&gt;%MACRO DO_MEDIAN;


	PROC MEANS DATA=SasHelp.PriceData NOPRINT;
		VAR 
      %DO I=1 %TO 17;
      price&amp;amp;I.
      %end;
      ; /* this semicolon ends the VAR statement*/
		OUTPUT OUT=work.Medians  
      Median=  %DO I=1 %TO 17; Med_&amp;amp;I. %end; 
      CV= %DO I=1 %TO 17; CV_&amp;amp;I. %end;
      ;
	RUN;


%MEND DO_MEDIAN;

%do_median;
&lt;/PRE&gt;
&lt;P&gt;to select the variables and specifically name them but in one pass instead of creating 17 different data sets.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 16:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545305#M150831</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-22T16:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: %MACRO and PROC MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545456#M150901</link>
      <description>&lt;P&gt;Most likely (I'm on my tablet, so can't test it at the moment) this happens:&lt;/P&gt;
&lt;PRE&gt;I=17&lt;/PRE&gt;
&lt;P&gt;is a boolean condition that evaluates to false (which is a numeric zero in SAS, as in most programming environments). The&amp;nbsp;&lt;EM&gt;text&lt;/EM&gt; "I" can never be equal to the&amp;nbsp;&lt;EM&gt;text&lt;/EM&gt; "17".&lt;/P&gt;
&lt;P&gt;So your macro do statement evaluates to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i = 1 %to 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the loop never executes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS iterative do statements differ from the "for" in C, where you would write&lt;/P&gt;
&lt;PRE&gt;for (i=1;i&amp;lt;=17;i++) {&lt;/PRE&gt;
&lt;P&gt;putting the continuation &lt;EM&gt;condition&lt;/EM&gt; in as the second element, not a &lt;EM&gt;target value&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 08:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545456#M150901</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-23T08:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: %MACRO and PROC MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545458#M150903</link>
      <description>&lt;P&gt;And to clear up a misconception:&lt;/P&gt;
&lt;P&gt;%macro is not a&amp;nbsp;&lt;EM&gt;procedure&lt;/EM&gt;, it is a&amp;nbsp;&lt;EM&gt;macro statement&lt;/EM&gt; that invokes the SAS macro preprocessor, so you are switching to a different syntactic environment that is similar in many aspects to Base SAS, but also vastly different in many others.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 08:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545458#M150903</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-23T08:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: %MACRO and PROC MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545481#M150910</link>
      <description>&lt;P&gt;What do you think is the upper value for I for this %do loop?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%DO I=1 %TO I=17;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What value do you get in the log if you run this statement?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put I=17;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 14:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/545481#M150910</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-23T14:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: %MACRO and PROC MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/552394#M153555</link>
      <description>&lt;P&gt;I am a little late responding, but I found the following article on %MACRO while studying. I hope this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi24/Handson/p149-24.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi24/Handson/p149-24.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2019 07:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-and-PROC-MEANS/m-p/552394#M153555</guid>
      <dc:creator>cnm8191</dc:creator>
      <dc:date>2019-04-19T07:21:09Z</dc:date>
    </item>
  </channel>
</rss>

