<?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 Questions about Macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631394#M20909</link>
    <description>&lt;P&gt;This may be a very basic question about macro, how could I make a macro code repeated conditions and table names?&lt;/P&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;If someone can tell me how to&amp;nbsp;solve it, I would really appreciate it.&lt;/SPAN&gt; &lt;SPAN&gt;Please!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original code is below;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data c1 c2 c3&amp;nbsp;…. c57; set xxxx;&lt;/P&gt;&lt;P&gt;if cnt=&amp;gt;1 and cnt=&amp;lt;16 then output c1;&lt;BR /&gt;if cnt=&amp;gt;2 and cnt&amp;lt;=17 then output c2;&lt;BR /&gt;if cnt=&amp;gt;3 and cnt&amp;lt;=18 then output c3;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;if cnt=&amp;gt;57 and cnt&amp;lt;=72 then output c57;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Mar 2020 21:58:16 GMT</pubDate>
    <dc:creator>JayChoi</dc:creator>
    <dc:date>2020-03-11T21:58:16Z</dc:date>
    <item>
      <title>Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631394#M20909</link>
      <description>&lt;P&gt;This may be a very basic question about macro, how could I make a macro code repeated conditions and table names?&lt;/P&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;If someone can tell me how to&amp;nbsp;solve it, I would really appreciate it.&lt;/SPAN&gt; &lt;SPAN&gt;Please!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original code is below;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data c1 c2 c3&amp;nbsp;…. c57; set xxxx;&lt;/P&gt;&lt;P&gt;if cnt=&amp;gt;1 and cnt=&amp;lt;16 then output c1;&lt;BR /&gt;if cnt=&amp;gt;2 and cnt&amp;lt;=17 then output c2;&lt;BR /&gt;if cnt=&amp;gt;3 and cnt&amp;lt;=18 then output c3;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;if cnt=&amp;gt;57 and cnt&amp;lt;=72 then output c57;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 21:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631394#M20909</guid>
      <dc:creator>JayChoi</dc:creator>
      <dc:date>2020-03-11T21:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631397#M20910</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/316185"&gt;@JayChoi&lt;/a&gt;&amp;nbsp; Something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro t;
 %do i=1 %to 57;
   if cnt=&amp;gt;&amp;amp;i and cnt=&amp;lt;%eval(&amp;amp;i+15) then output c&amp;amp;i;
 %end;
%mend t;

%t&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can call the macro using %t in the datastep&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 22:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631397#M20910</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-11T22:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631400#M20911</link>
      <description>&lt;P&gt;Since you are new to SAS, maybe you should start by explaining what you are trying to do, the big picture and not the writing of a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you going to do with 57 different data sets? Why not one large data set, with some sort of ID value so you can analyze everything at once with BY group processing.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 22:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631400#M20911</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-11T22:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631407#M20912</link>
      <description>&lt;P&gt;&amp;nbsp;I really thank you. But all data sets (c1, c2, c3...….c57) have to be extracted for each condition (if cnt=&amp;gt;1 and cnt=&amp;lt;16 then output c1;&lt;BR /&gt;if cnt=&amp;gt;2 and cnt&amp;lt;=17 then output c2;...….if cnt=&amp;gt;57 and cnt&amp;lt;=72 then output c57;) from "xxxx" data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;Here, cnt=1 means one quarter, and one dataset contains 16 quarters.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;Could you explain me more?&lt;/DIV&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;Thank you!&lt;/DIV&gt;</description>
      <pubDate>Wed, 11 Mar 2020 22:26:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631407#M20912</guid>
      <dc:creator>JayChoi</dc:creator>
      <dc:date>2020-03-11T22:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631408#M20913</link>
      <description>&lt;P&gt;I really thank you for your answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;I would like to extract a separate data set for each 16 quarters (cnt=1 means one quarter)&amp;nbsp;from a large data set (xxxx), calculate the estimates through regression analysis with each sub data set, and then combine them into one large data set.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;In other words, I need to create separate data sets, such as cnt 1 through 16 (from cnt=1 to 16), cnt 2 through 16 (from cnt=2 to 17), etc.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;Could you help me more? &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 11 Mar 2020 22:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631408#M20913</guid>
      <dc:creator>JayChoi</dc:creator>
      <dc:date>2020-03-11T22:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631409#M20914</link>
      <description>&lt;P&gt;This is exactly why you keep everything in one data set, and use BY group processing on the one data set, to perform all these 57 regressions with a very small amount of code, and then the results would be out into a single data set.&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 11 Mar 2020 22:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631409#M20914</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-11T22:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631411#M20915</link>
      <description>Thank you for your answer. I mean I have to make sub data sets from a large data set "xxxx". The data set xxxx has various variables as well as a quarter variable.&lt;BR /&gt;So, like the inefficient code I showed you earlier, I'd like to create efficient macro code that creates each data set.</description>
      <pubDate>Wed, 11 Mar 2020 22:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631411#M20915</guid>
      <dc:creator>JayChoi</dc:creator>
      <dc:date>2020-03-11T22:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631412#M20916</link>
      <description />
      <pubDate>Wed, 11 Mar 2020 22:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631412#M20916</guid>
      <dc:creator>JayChoi</dc:creator>
      <dc:date>2020-03-11T22:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631415#M20917</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/316185"&gt;@JayChoi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&amp;nbsp;I mean I have to make sub data sets from a large data set "xxxx". &lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, you don't have to make sub-data sets. This is inefficient and makes your programming harder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;The data set xxxx has various variables as well as a quarter variable.&lt;BR /&gt;So, like the inefficient code I showed you earlier, I'd like to create efficient macro code that creates each data set.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macros are completely the wrong tool here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The general outline of what you want to do is have one data set, where each record has an index indicating which of the 57 groups it belongs to (and possibly it can belong to more than one group), then your run your modeling PROC one time, with a BY statement, and then all the results are output into one data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like you are trying to perform rolling regressions on your 57 time periods. If you search the internet you will find SAS code to perform rolling regressions, you don't have to write your own regression code for 57 data sets.&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 11 Mar 2020 23:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631415#M20917</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-11T23:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631418#M20919</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/316185"&gt;@JayChoi&lt;/a&gt;&amp;nbsp; Please post a brief description of the bigger picture/objective i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Please post a sample of your input dataset (mock sample will do)&lt;/P&gt;
&lt;P&gt;2. Please post a sample of your expected output for the input sample&lt;/P&gt;
&lt;P&gt;3. Please post the business dervation logic to arrive at the expected output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A complete and comprehensive information would enable the community to provide you with a complete solution.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 23:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631418#M20919</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-11T23:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631433#M20921</link>
      <description>&lt;P&gt;A number of posters have already told you that you're heading in a poor direction by trying to create so many subsets.&amp;nbsp; But the solutions they offer aren't all that helpful.&amp;nbsp; Here's a reasonable approach that you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
   %local i;
   %do i=1 %to 57;
      data temp /view = temp;
         set xxxx;
         where &amp;amp;i &amp;lt;= cnt &amp;lt;= &amp;amp;i + 16;
      run;
      proc reg data=temp;
         /* the rest of the code goes here,  */
         /* which might include more than    */
         /* proc reg                         */
      run;
   %end;
%mend test;

%test&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This way, you can properly subset the observations for each iteration, based on your original data set.&amp;nbsp; But you never have to create any subsets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to use a subset more than once (such as for a series of PROC steps), skip creating a view.&amp;nbsp; Just create the data set itself, as a temporary data set, with the same name each time.&amp;nbsp; Any output data sets that you want to create and save can take on different names by making &amp;amp;I part of the name.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 02:23:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631433#M20921</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-03-12T02:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631503#M20941</link>
      <description>&lt;P&gt;Rolling regressions in SAS without macros&lt;/P&gt;
&lt;P&gt;&lt;A href="http://pages.stern.nyu.edu/~adesouza/sasfinphd/index/node25.html" target="_blank"&gt;http://pages.stern.nyu.edu/~adesouza/sasfinphd/index/node25.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/rolling-window-by-quarter/m-p/343747#M63427" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/rolling-window-by-quarter/m-p/343747#M63427&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46964#M12554" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46964#M12554&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 10:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631503#M20941</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-12T10:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631762#M20985</link>
      <description>&lt;P&gt;Now I can understand what you said fully. You explained more than what I asked. I mean you taught me until the last step of my works.&lt;/P&gt;&lt;P&gt;I really appreciate you. If you are ok, I'd like to ask you many things. Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 01:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Questions-about-Macro/m-p/631762#M20985</guid>
      <dc:creator>JayChoi</dc:creator>
      <dc:date>2020-03-13T01:47:33Z</dc:date>
    </item>
  </channel>
</rss>

