<?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: SAS macro programming (uses DO loop inside a Macro function) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405570#M98686</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34991"&gt;@nstdt&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The outer loop is supposed to handle the next&amp;nbsp;group of 5 words.&lt;/P&gt;
&lt;P&gt;The inner loop indexed by J&amp;nbsp; runs from ` to 5, then the outer index I becomes 6: so that J now runs from 6 to 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously eventually I hope to extend it to handle 1000 variables (in my dataset transf_vars).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure how I would do the breaking down (keeping adjacent sets of 5 variables together)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You don't need the "j" loop at all.&lt;/P&gt;
&lt;P&gt;The first iteration of the outer loop will create dataset words_1 with variables 1 to 5, the next will create words_6 with vars 6 to 10, and so on.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Oct 2017 14:43:21 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-10-19T14:43:21Z</dc:date>
    <item>
      <title>SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405544#M98673</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;My problem is to break up a large data-set&amp;nbsp;into smaller ones as below.&lt;/P&gt;
&lt;P&gt;I have a data set containing about ~1000 variables.&amp;nbsp;I converted each of these variable names to macro-variables called: varname1,varname2,,,varname100,...etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I need to generate smaller data-sets , each containing only 5 variables. For example, I tried the following SAS macro code but I get&amp;nbsp;an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro batch_Chk(start,fin);

%do i =&amp;amp;start %to &amp;amp;fin by 5;
%let res=%evalf(&amp;amp;i. + 4);

	%do j =&amp;amp;i. %to &amp;amp;res. by 1;

		data words_&amp;amp;i.;   /* Words_i are the sub-data-sets with 5 variables each */
		set transf_vars; /* Transf_vars is the Original data */
		%put &amp;amp;res;       /* check res value...*/
		keep &amp;amp;&amp;amp;varname&amp;amp;i.- &amp;amp;&amp;amp;varname&amp;amp;res.;
	%end;
run;
%end;
%mend;

%batch_Chk (1,10);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable START resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable FIN resolves to 10&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;BR /&gt; operand is required. The condition was: &amp;amp;fin by 5&lt;BR /&gt;ERROR: The %TO value of the %DO I loop is invalid.&lt;BR /&gt;ERROR: The macro BATCH_CHK will stop executing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My goal is to have the 1000 variables (along with their content)&amp;nbsp; broken into smaller data-sets with just 5 variables each.&lt;/P&gt;
&lt;P&gt;I initially thought I could change the variable names to macro-variables and manipulate them inside a DO loop - but I am not getting the results I hoped for. Would really appreciate any advise or help about this problem!&lt;/P&gt;
&lt;P&gt;Thanks very much!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405544#M98673</guid>
      <dc:creator>nstdt</dc:creator>
      <dc:date>2017-10-19T14:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405556#M98675</link>
      <description>&lt;P&gt;Proper visual formatting will make solving your issues easier:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro batch_Chk(start,fin);
%do i = &amp;amp;start %to &amp;amp;fin by 5;
  %let res=%evalf(&amp;amp;i. + 4);
  %do j =&amp;amp;i. %to &amp;amp;res. by 1;
    data words_&amp;amp;i.; /* words_i is a subset data with 5 variables*/
    set transf_vars; /* transf_vars is the Original Data w/all Variables*/
    %put &amp;amp;res;
    %put &amp;amp;res;
    keep &amp;amp;&amp;amp;varname&amp;amp;i.- &amp;amp;&amp;amp;varname&amp;amp;res.;
  %end;
    run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can immediately see that a %end is missing.&lt;/P&gt;
&lt;P&gt;But your macro already coughs up at "by", as that is not a macro keyword.&lt;/P&gt;
&lt;P&gt;Fixing that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro batch_Chk(start,fin);
%do i = &amp;amp;start %to &amp;amp;fin %by 5;
  %let res=%evalf(&amp;amp;i. + 4);
  %do j =&amp;amp;i. %to &amp;amp;res. by 1;
    %put &amp;amp;res;
    data words_&amp;amp;i.; /* words_i is a subset data with 5 variables*/
    set transf_vars; /* transf_vars is the Original Data w/all Variables*/
    keep &amp;amp;&amp;amp;varname&amp;amp;i.- &amp;amp;&amp;amp;varname&amp;amp;res.;
    run;
  %end;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Moved the %put &amp;amp;res; to a place where it is easier to understand, and removed the second identical statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But where do you get the 1000 macro variables varname1 to varname1000 from?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405556#M98675</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-19T14:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405562#M98679</link>
      <description>&lt;P&gt;Ups, just saw that the inner %do loop makes no sense at all:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro batch_Chk(start,fin);
%do i = &amp;amp;start %to &amp;amp;fin %by 5;
  %let res=%evalf(&amp;amp;i. + 4);
  %put &amp;amp;res;
  data words_&amp;amp;i.; /* words_i is a subset data with 5 variables*/
  set transf_vars; /* transf_vars is the Original Data w/all Variables*/
  keep &amp;amp;&amp;amp;varname&amp;amp;i.- &amp;amp;&amp;amp;varname&amp;amp;res.;
  run;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405562#M98679</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-19T14:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405563#M98680</link>
      <description>Hi Kurt,&lt;BR /&gt;thanks for your reply. I noticed the %END was missing myself - and then from your post I have fixed the %BY also.&lt;BR /&gt;&lt;BR /&gt;But I still get an ERROR:&lt;BR /&gt;&lt;BR /&gt;SYMBOLGEN:  Macro variable START resolves to 1&lt;BR /&gt;SYMBOLGEN:  Macro variable FIN resolves to 10&lt;BR /&gt;WARNING: Apparent invocation of macro EVALF not resolved.&lt;BR /&gt;SYMBOLGEN:  Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN:  Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN:  Macro variable RES resolves to %evalf(1 + 4)&lt;BR /&gt;WARNING: Apparent invocation of macro EVALF not resolved.&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;BR /&gt;       operand is required. The condition was: &amp;amp;res.&lt;BR /&gt;ERROR: The %TO value of the %DO J loop is invalid.&lt;BR /&gt;ERROR: The macro BATCH_CHK will stop executing.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405563#M98680</guid>
      <dc:creator>nstdt</dc:creator>
      <dc:date>2017-10-19T14:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405564#M98681</link>
      <description>&lt;P&gt;That's because there is no %evalf function, you probably meant %sysevalf, but that is overkill, as we only work with integer values here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro batch_Chk(start,fin);
%do i = &amp;amp;start %to &amp;amp;fin %by 5;
  %let res=%eval(&amp;amp;i. + 4);
  %put &amp;amp;res;
  data words_&amp;amp;i.; /* words_i is a subset data with 5 variables*/
  set transf_vars; /* transf_vars is the Original Data w/all Variables*/
  keep &amp;amp;&amp;amp;varname&amp;amp;i.- &amp;amp;&amp;amp;varname&amp;amp;res.;
  run;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405564#M98681</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-19T14:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405565#M98682</link>
      <description>&lt;P&gt;The outer loop is supposed to handle the next&amp;nbsp;group of 5 words.&lt;/P&gt;
&lt;P&gt;The inner loop indexed by J&amp;nbsp; runs from ` to 5, then the outer index I becomes 6: so that J now runs from 6 to 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously eventually I hope to extend it to handle 1000 variables (in my dataset transf_vars).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure how I would do the breaking down (keeping adjacent sets of 5 variables together)&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405565#M98682</guid>
      <dc:creator>nstdt</dc:creator>
      <dc:date>2017-10-19T14:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405568#M98684</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As posted that code will not compile the macro as there is an unclosed %do statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You want %by not by in the loop&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you aren't actually using the macro variable J any where why is it there? As written it will overwrite the data set words&amp;amp;i 5 times (if the by issue gets fixed)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strongly suggest that before actually manipulating your data that you just print out the index values&amp;nbsp;and resolved values of the variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a hard time seeing a good use for this operation though. Especially since most of the data sets following the logic you attempted would not have identification variables to allow easy realignment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tested code would require an example input data set and the macro variables varname1 to varnamennn.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if the number of variables is not an integer multiple of 5 you'll get errors for the last "set".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:40:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405568#M98684</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-19T14:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405570#M98686</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34991"&gt;@nstdt&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The outer loop is supposed to handle the next&amp;nbsp;group of 5 words.&lt;/P&gt;
&lt;P&gt;The inner loop indexed by J&amp;nbsp; runs from ` to 5, then the outer index I becomes 6: so that J now runs from 6 to 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously eventually I hope to extend it to handle 1000 variables (in my dataset transf_vars).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure how I would do the breaking down (keeping adjacent sets of 5 variables together)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You don't need the "j" loop at all.&lt;/P&gt;
&lt;P&gt;The first iteration of the outer loop will create dataset words_1 with variables 1 to 5, the next will create words_6 with vars 6 to 10, and so on.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405570#M98686</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-19T14:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405571#M98687</link>
      <description>&lt;P&gt;Thanks for the help!&lt;/P&gt;
&lt;P&gt;Your version runs, though it throws an error which I should have anticipated:&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable VARNAME5 resolves to AVGEARN_NSA&lt;BR /&gt;ERROR: Missing numeric suffix on a numbered variable list (AUTO_REPO_DIRECT-AVGEARN_NSA).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that though I have the macro-variables names set up as varname1, varname2,...,varname1000,&lt;/P&gt;
&lt;P&gt;when SAS dereferences them, the ordering is lost -the actual names inside varname1 , varname2 , etc. are not similar to each other at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again for your help , but if you have any ideas how I go about creating these sus-data-set form the original data (actually it has exactly 726 names), please do&amp;nbsp; help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405571#M98687</guid>
      <dc:creator>nstdt</dc:creator>
      <dc:date>2017-10-19T14:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405573#M98688</link>
      <description>&lt;P&gt;Now that can be solved with an inner loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro batch_Chk(start,fin);
%do i = &amp;amp;start %to &amp;amp;fin %by 5;
  %let res=%eval(&amp;amp;i. + 4);
  data words_&amp;amp;i.; /* words_i is a subset data with 5 variables*/
  set transf_vars; /* transf_vars is the Original Data w/all Variables*/
  keep
  %do j = &amp;amp;i %to &amp;amp;res;
    &amp;amp;&amp;amp;varname&amp;amp;j.
  %end;
  ;
  run;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:47:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405573#M98688</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-19T14:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405574#M98689</link>
      <description>&lt;P&gt;Use the SASHELP.VTABLE data which includes the VARNUM so you can control the ordering of your variables.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405574#M98689</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-19T14:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405575#M98690</link>
      <description>&lt;P&gt;You said:&lt;/P&gt;
&lt;P&gt;I have a hard time seeing a good use for this operation though. Especially since most of the data sets following the logic you attempted would not have identification variables to allow easy realignment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're right, the resolved names of the macro-variables do not have any oredring pattern and I get errors.&lt;/P&gt;
&lt;P&gt;So I'm back to Square-One - How do I break down a dataset of 726 variables into smaller data-sets with just 5 variables each?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405575#M98690</guid>
      <dc:creator>nstdt</dc:creator>
      <dc:date>2017-10-19T14:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405579#M98691</link>
      <description>&lt;P&gt;Why are you doing this in the first place? If there's a valid reason, there's usually a way to organize the data that makes sense contextually. Are you trying to make a fact/dim type structure to reduce the size of the data set?&lt;/P&gt;
&lt;P&gt;Breaking things into groups of 5 seems like a strange decision. Why not 10 or 12?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405579#M98691</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-19T14:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405580#M98692</link>
      <description>&lt;P&gt;Hi Kurt - thank , this works!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am now going to try and extend this to my original data-set, which actually has 726 variables (not 1000, and so the last loop may&amp;nbsp; have some issues). Will try to work around or post back here!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405580#M98692</guid>
      <dc:creator>nstdt</dc:creator>
      <dc:date>2017-10-19T14:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405587#M98693</link>
      <description>&lt;P&gt;Good question, and I will explain the details, hoping maybe a better way to do things might come out of it!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 726 econometric variables - and I need to check their Time Series Stationarity. This check is done in a macro which produces very long reports-&lt;/P&gt;
&lt;P&gt;making it hard to read if there are lots of variables - even 5 can be hard to read, since there are a lot of output stats.&lt;/P&gt;
&lt;P&gt;Yes, I thought about having 10 variables in each groups, but I thought it would make it hard to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, I thought I would try and produce smaller data-sets, with the variables just selected from adjacent groups of 5.&lt;/P&gt;
&lt;P&gt;I've seen SAS code where you can say "Keep A1-A5" in the data-step and was hoping for something similar.&lt;/P&gt;
&lt;P&gt;But the underlying original variable names (once your esolve varname1,varname2 etc.) are not similar at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So SAS complained again, but I'm now trying to refine Kurt's latest code - I think it works , just that it makes the last data-set empty (because I have 726 rather than 1000 names - not divisible by 5).&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 15:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405587#M98693</guid>
      <dc:creator>nstdt</dc:creator>
      <dc:date>2017-10-19T15:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405589#M98694</link>
      <description>&lt;P&gt;Change the macro to take another parameter - a list of variables and add the KEEP to the data step to filter the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then call the macro with&amp;nbsp;your variable lists.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 15:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405589#M98694</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-19T15:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405590#M98695</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an alternative program :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro breakup;

	%let n=1000;
	%let n1=5;
	%let nds=%eval(&amp;amp;n./&amp;amp;n1.);

	%if %eval(&amp;amp;nds.*&amp;amp;n1.) ne &amp;amp;n. %then %do;
		%let nds=&amp;amp;nds.+1;
	%end;

	proc sql noprint;
		SELECT NAME
		INTO :varlist SEPARATED BY " "
		FROM dictionary.columns
		WHERE LIBNAME="WORK" AND MEMNAME="HAVE";
	quit;

	data
		%do i=1 %to &amp;amp;nds.;
		have_&amp;amp;i ( keep=%scan(&amp;amp;varlist.,&amp;amp;n1.*(&amp;amp;i.-1)+1," ") -- %scan(&amp;amp;varlist.,%sysfunc(min(&amp;amp;n1.*&amp;amp;i.,&amp;amp;n.))," ") )
		%end;
		;
		set have;
	run;
%mend;

%breakup;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the total number of variables is not a multiple of the number of variables per dataset, you'll have&lt;/P&gt;
&lt;P&gt;to manually create the dataset for the remaining columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt; I have edited the program to handle all cases.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 15:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405590#M98695</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-10-19T15:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405602#M98698</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I took your solution, but I have to add that that I shifted the indexes to 6 and 5 instead of 5 and 4 - since I actually have 726 variables (divisible by 6 and only one more that 5, so the final report can still be read - just barely), and not 1000.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks very much again! Especially for catching all the small mistakes which I hadn't noticed despite staring at them for a long time!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you think of a better way to break-up a data-set with ~1000 variables into smaller datasets, please let me know on this thread!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 15:24:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405602#M98698</guid>
      <dc:creator>nstdt</dc:creator>
      <dc:date>2017-10-19T15:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405606#M98700</link>
      <description>&lt;P&gt;Thanks for the alternative solution! I plan to go through it as well and understand it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought it was a simple task - break down a large dataset into smaller blocks of 5-6 variables each. But the implementation&lt;/P&gt;
&lt;P&gt;turned out harder than I thought &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 15:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405606#M98700</guid>
      <dc:creator>nstdt</dc:creator>
      <dc:date>2017-10-19T15:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro programming (uses DO loop inside a Macro function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405608#M98701</link>
      <description>&lt;P&gt;I would second going with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;&amp;nbsp;solution, with a small modification, the addition of an ORDER BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;	&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt; noprint&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
		&lt;SPAN class="token statement"&gt;SELECT&lt;/SPAN&gt; NAME
		&lt;SPAN class="token keyword"&gt;INTO&lt;/SPAN&gt; :varlist SEPARATED &lt;SPAN class="token statement"&gt;BY&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;" "&lt;/SPAN&gt;
		&lt;SPAN class="token keyword"&gt;FROM&lt;/SPAN&gt; dictionary&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;columns&lt;/SPAN&gt;
		&lt;SPAN class="token statement"&gt;WHERE&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;LIBNAME&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"WORK"&lt;/SPAN&gt; AND MEMNAME&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"HAVE"&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;                Order by VARNUM;&lt;/SPAN&gt;
	&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 15:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-programming-uses-DO-loop-inside-a-Macro-function/m-p/405608#M98701</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-19T15:34:20Z</dc:date>
    </item>
  </channel>
</rss>

