<?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 simple macro question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83681#M18056</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to use a simple macro and it does not appear to be doing what i am intending it to do.&amp;nbsp; I would like to write a macro to sort 4 data sets by the same variable, called num.&amp;nbsp; The data set names differ by a numeric value.&amp;nbsp; For example the first data set is called data1, the second data2, the third data3, and the fourth data4.&amp;nbsp; All four data sets are in my work library.&amp;nbsp; Below is the code I tried to use.&amp;nbsp; Any input you have would be very helpful.&amp;nbsp; I know I can use 4 proc sorts to get this done but was attempting to do this through a macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro srt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sort&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data=data&amp;amp;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by num;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend srt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Nov 2012 00:03:09 GMT</pubDate>
    <dc:creator>jdub</dc:creator>
    <dc:date>2012-11-29T00:03:09Z</dc:date>
    <item>
      <title>simple macro question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83681#M18056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to use a simple macro and it does not appear to be doing what i am intending it to do.&amp;nbsp; I would like to write a macro to sort 4 data sets by the same variable, called num.&amp;nbsp; The data set names differ by a numeric value.&amp;nbsp; For example the first data set is called data1, the second data2, the third data3, and the fourth data4.&amp;nbsp; All four data sets are in my work library.&amp;nbsp; Below is the code I tried to use.&amp;nbsp; Any input you have would be very helpful.&amp;nbsp; I know I can use 4 proc sorts to get this done but was attempting to do this through a macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro srt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sort&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data=data&amp;amp;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by num;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend srt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Nov 2012 00:03:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83681#M18056</guid>
      <dc:creator>jdub</dc:creator>
      <dc:date>2012-11-29T00:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: simple macro question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83682#M18057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are ending your loop too quickly and didn't specify the macro variable.&amp;nbsp; Try (untested):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%macro srt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to 4;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sort&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data=data&amp;amp;i;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by num;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%mend srt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%srt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Nov 2012 00:07:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83682#M18057</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-29T00:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: simple macro question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83683#M18058</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I tried this but now I get an error message of:&lt;/P&gt;&lt;P&gt;File WORK.DATA5.DATA does not exist.&lt;/P&gt;&lt;P&gt;I consider this an improvement as nothing was posting in my log before.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to macros and am curious why you included the %srt at the end.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Nov 2012 00:18:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83683#M18058</guid>
      <dc:creator>jdub</dc:creator>
      <dc:date>2012-11-29T00:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: simple macro question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83684#M18059</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;/* create sample datasets */&lt;/P&gt;&lt;P&gt;data data1 data2 data3 data4;&lt;/P&gt;&lt;P&gt;input num @@;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;2 4 6 4 1 38 9&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* define your macro */&lt;/P&gt;&lt;P&gt;%macro srt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sort&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data=data&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by num;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend srt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* using the macro created */&lt;/P&gt;&lt;P&gt;%srt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Nov 2012 00:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83684#M18059</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-11-29T00:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: simple macro question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83685#M18060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The statements from %MACRO to %MEND just define the macro. To actually run it you need call it.&amp;nbsp; That is why Art included the %SRT at the end of the program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are seeing a message about DATA5 after running the macro as defined then it looks like you are trying to reference the macro variable i after the macro has finished.&amp;nbsp; You might want to add a %LOCAL statement to your macro definition so that looping over I does not modify an existing macro variable in an outer scope.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro srt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %local i ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %do i=1 %to 4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sort &lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data=data&amp;amp;i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by num;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend srt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%srt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Nov 2012 00:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83685#M18060</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-11-29T00:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: simple macro question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83686#M18061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh shoot, thank you both Arthur and Linlin - the code worked - it was &amp;lt;again&amp;gt; human error on my part&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Nov 2012 00:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-macro-question/m-p/83686#M18061</guid>
      <dc:creator>jdub</dc:creator>
      <dc:date>2012-11-29T00:34:34Z</dc:date>
    </item>
  </channel>
</rss>

