<?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 Looping through dataset library with macro function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682094#M206451</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created list of datasets in my library (called block) using below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents data=block._all_ noprint out=contents (keep=libname memname);&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=contents nodup;&lt;BR /&gt;by libname memname;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I like to loop through all of these datasets and apply the split macro below to each dataset.&lt;/P&gt;&lt;P&gt;Since I have &amp;gt;200 datasets, how do I this without having to do it write split macro individually for each dataset.&amp;nbsp; I'm having quite a bit trouble with this.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=""&gt;%macro split &lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;SRC_DATASET=, OUT_PREFIX=, SPLIT_NUM=, SPLIT_DEF=&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
/* Parameters:
/*   SRC_DATASET - name of the source data set     */
/*   OUT_PREFIX - prefix of the output data sets   */
/*   SPLIT_NUM - split number                      */
/*   SPLIT_DEF - split definition &lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;=SETS or =NOBS&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt; */
&amp;nbsp;
   %local I K S TLIST;
&amp;nbsp;
   /* number of observations &amp;amp;K, number of smaller datasets &amp;amp;S */
   data _null_;
      if &lt;SPAN&gt;0&lt;/SPAN&gt; then set &amp;amp;SRC_DATASET nobs=N;
      if upcase&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;"&amp;amp;SPLIT_DEF"&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;='NOBS' then
         do;
            call symputx&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;'K',&amp;amp;SPLIT_NUM&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;; 
            call symputx&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;'S',ceil&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;N/&amp;amp;SPLIT_NUM&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
            put "***MACRO SPLIT: Splitting into datasets of no more than &amp;amp;SPLIT_NUM observations";
         end;
         else if upcase&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;"&amp;amp;SPLIT_DEF"&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;='SETS' then
         do;
            call symputx&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;'S',&amp;amp;SPLIT_NUM&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;; 
            call symputx&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;'K',ceil&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;N/&amp;amp;SPLIT_NUM&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
            put "***MACRO SPLIT: Splitting into &amp;amp;SPLIT_NUM datasets";
        end;
         else put "***MACRO SPLIT: Incorrect SPLIT_DEF=&amp;amp;SPLIT_DEF value. Must be either SETS or NOBS.";
      stop; 
   run;
&amp;nbsp;
   /* terminate macro if nothing to split */
   %if &lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&amp;amp;K le &lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt; or &lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&amp;amp;S le &lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt; %then %return;
&amp;nbsp;
    /* generate list of smaller dataset names */
   %do I=&lt;SPAN&gt;1&lt;/SPAN&gt; %to &amp;amp;S;
      %let TLIST = &amp;amp;TLIST &amp;amp;OUT_PREFIX._&amp;amp;I;
   %end;
&amp;nbsp;
   /* split source dataset into smaller datasets */
   data &amp;amp;TLIST;
      set &amp;amp;SRC_DATASET;
      select;
         %do I=&lt;SPAN&gt;1&lt;/SPAN&gt; %to &amp;amp;S;
            when&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;_n_ &amp;lt;= &amp;amp;K * &amp;amp;I&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt; output &amp;amp;OUT_PREFIX._&amp;amp;I; 
         %end;
      end;
   run;
&amp;nbsp;
%mend split; &amp;nbsp;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Sep 2020 02:48:48 GMT</pubDate>
    <dc:creator>edhuang</dc:creator>
    <dc:date>2020-09-08T02:48:48Z</dc:date>
    <item>
      <title>Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682094#M206451</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created list of datasets in my library (called block) using below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents data=block._all_ noprint out=contents (keep=libname memname);&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=contents nodup;&lt;BR /&gt;by libname memname;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I like to loop through all of these datasets and apply the split macro below to each dataset.&lt;/P&gt;&lt;P&gt;Since I have &amp;gt;200 datasets, how do I this without having to do it write split macro individually for each dataset.&amp;nbsp; I'm having quite a bit trouble with this.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=""&gt;%macro split &lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;SRC_DATASET=, OUT_PREFIX=, SPLIT_NUM=, SPLIT_DEF=&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
/* Parameters:
/*   SRC_DATASET - name of the source data set     */
/*   OUT_PREFIX - prefix of the output data sets   */
/*   SPLIT_NUM - split number                      */
/*   SPLIT_DEF - split definition &lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;=SETS or =NOBS&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt; */
&amp;nbsp;
   %local I K S TLIST;
&amp;nbsp;
   /* number of observations &amp;amp;K, number of smaller datasets &amp;amp;S */
   data _null_;
      if &lt;SPAN&gt;0&lt;/SPAN&gt; then set &amp;amp;SRC_DATASET nobs=N;
      if upcase&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;"&amp;amp;SPLIT_DEF"&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;='NOBS' then
         do;
            call symputx&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;'K',&amp;amp;SPLIT_NUM&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;; 
            call symputx&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;'S',ceil&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;N/&amp;amp;SPLIT_NUM&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
            put "***MACRO SPLIT: Splitting into datasets of no more than &amp;amp;SPLIT_NUM observations";
         end;
         else if upcase&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;"&amp;amp;SPLIT_DEF"&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;='SETS' then
         do;
            call symputx&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;'S',&amp;amp;SPLIT_NUM&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;; 
            call symputx&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;'K',ceil&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;N/&amp;amp;SPLIT_NUM&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
            put "***MACRO SPLIT: Splitting into &amp;amp;SPLIT_NUM datasets";
        end;
         else put "***MACRO SPLIT: Incorrect SPLIT_DEF=&amp;amp;SPLIT_DEF value. Must be either SETS or NOBS.";
      stop; 
   run;
&amp;nbsp;
   /* terminate macro if nothing to split */
   %if &lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&amp;amp;K le &lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt; or &lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&amp;amp;S le &lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt; %then %return;
&amp;nbsp;
    /* generate list of smaller dataset names */
   %do I=&lt;SPAN&gt;1&lt;/SPAN&gt; %to &amp;amp;S;
      %let TLIST = &amp;amp;TLIST &amp;amp;OUT_PREFIX._&amp;amp;I;
   %end;
&amp;nbsp;
   /* split source dataset into smaller datasets */
   data &amp;amp;TLIST;
      set &amp;amp;SRC_DATASET;
      select;
         %do I=&lt;SPAN&gt;1&lt;/SPAN&gt; %to &amp;amp;S;
            when&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;_n_ &amp;lt;= &amp;amp;K * &amp;amp;I&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt; output &amp;amp;OUT_PREFIX._&amp;amp;I; 
         %end;
      end;
   run;
&amp;nbsp;
%mend split; &amp;nbsp;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 02:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682094#M206451</guid>
      <dc:creator>edhuang</dc:creator>
      <dc:date>2020-09-08T02:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682097#M206453</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set CONTENTS;
  call execute(catt('%split(ds=BLOCK.',MEMNAME,',out_prefix=_a,split_num=200);'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 03:06:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682097#M206453</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-08T03:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682108#M206457</link>
      <description>&lt;P&gt;Hi Chris,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your quick reply.&lt;/P&gt;&lt;P&gt;I tried yours method, but it is not working for me. I don't get any new datasets output to my work library.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I have about 237 dataset labeled as below&lt;/P&gt;&lt;P&gt;block.block_A, block.block_B, block.block_C.....&lt;/P&gt;&lt;P&gt;Each dataset have roughly about 600 observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to split each dataset into smaller dataset (let's just say 200 observations each).&lt;/P&gt;&lt;P&gt;So if block.block_A has 630 observations and I use&lt;/P&gt;&lt;P&gt;%split (block.block_A, want.block_A, 200, nobs) then I will get&lt;/P&gt;&lt;P&gt;want.block_A_1 with 200 obs&lt;/P&gt;&lt;P&gt;want.block_A_2 with 200 obs&lt;/P&gt;&lt;P&gt;want.block_A_3 with 200 obs&lt;/P&gt;&lt;P&gt;want.block_A_4 with 30 obs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I like to do this for each of my 237 datasets without having use write the %split macro above for each dataset.&amp;nbsp; If each of my dataset has 600 observations, then I expect to have&lt;/P&gt;&lt;P&gt;237*3=711 new datasets (200 obs each) after applying the split macro.&lt;/P&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;</description>
      <pubDate>Tue, 08 Sep 2020 04:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682108#M206457</guid>
      <dc:creator>edhuang</dc:creator>
      <dc:date>2020-09-08T04:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682115#M206460</link>
      <description>&lt;P&gt;It seems that Chris forgot the SPLIT_DEF parameter in the macro-call, adding it should solve the issue.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 04:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682115#M206460</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-09-08T04:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682120#M206461</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;&amp;nbsp;I don't get any new datasets output to my work library.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;What's in the log?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More importantly, what's the point of creating all these tables rather than using data set options?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 05:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682120#M206461</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-08T05:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682411#M206557</link>
      <description>&lt;P&gt;Hi Chris,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have an easier way of splitting all of these datasets using data set, please share.&amp;nbsp; I would love to try it.&amp;nbsp; May be I am overlooking something that can be solved quite easily.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set contents;&lt;BR /&gt;by memname;&lt;BR /&gt;call execute (catt('%split(SRC_DATASET=block.',memname,', OUT_PREFIX=_a, SPLIT_NUM=200, SPLIT_DEF=NOBS);'));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The logs are below - I am getting this for each of the dataset.&lt;/P&gt;&lt;P&gt;NOTE: CALL EXECUTE generated line.&lt;BR /&gt;1 + data _null_; if 0 then set block.BLOCK_10 nobs=N; if upcase("NOBS")='NOBS' then do;&lt;BR /&gt;call symputx('K',200); call symputx('S',ceil(N/200)); put "***MACRO SPLIT: Splitting into datasets of no&lt;BR /&gt;more&lt;BR /&gt;2 + than 200 observations"; end; else if upcase("NOBS")='SETS' then do; call&lt;BR /&gt;symputx('S',200); call symputx('K',ceil(N/200)); put "***MACRO SPLIT: Splitting into 200 datasets";&lt;BR /&gt;end;&lt;BR /&gt;3 + else put "***MACRO SPLIT: Incorrect SPLIT_DEF=NOBS value. Must be either SETS or NOBS."; stop; run;&lt;/P&gt;&lt;P&gt;***MACRO SPLIT: Splitting into datasets of no more than 200 observations&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After doing some research, I thought it may be the order in which the variables are being executed.&amp;nbsp; So I also tried with %nrstr, but I'm don't think I am doing this right since it is giving errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set contents;&lt;BR /&gt;by memname;&lt;BR /&gt;if first.memname;&lt;BR /&gt;call execute ('%nrstr(cat('%split(SRC_DATASET=block.',memname,', OUT_PREFIX=_a, SPLIT_NUM=200, SPLIT_DEF=NOBS)'))');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log is saying:&lt;/P&gt;&lt;P&gt;NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR&lt;BR /&gt;24&lt;BR /&gt;25 GOPTIONS ACCESSIBLE;&lt;BR /&gt;26&lt;BR /&gt;27 data _null_;&lt;BR /&gt;28 set contents;&lt;BR /&gt;29 by memname;&lt;BR /&gt;30&lt;BR /&gt;31 call execute ('%nrstr(catt('%split(SRC_DATASET=block.',memname,', OUT_PREFIX=_a, SPLIT_NUM=200, SPLIT_DEF=NOBS);'))');&lt;BR /&gt;NOTE: Line generated by the invoked macro "SPLIT".&lt;BR /&gt;31 data _null_; if 0 then&lt;BR /&gt;___&lt;BR /&gt;388&lt;BR /&gt;76&lt;BR /&gt;ERROR: Invalid date/time/datetime constant '%nrstr(catt('d.&lt;BR /&gt;ERROR: File ,memname, does not exist.&lt;/P&gt;&lt;P&gt;______________&lt;BR /&gt;77&lt;BR /&gt;NOTE: Line generated by the macro variable "SRC_DATASET".&lt;BR /&gt;31 block.',memname,'&lt;BR /&gt;______&lt;BR /&gt;22&lt;BR /&gt;201&lt;/P&gt;&lt;P&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;ERROR 77-185: Invalid number conversion on '%nrstr(catt('d.&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS,&lt;BR /&gt;NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;/P&gt;&lt;P&gt;ERROR 201-322: The option is not recognized and will be ignored.&lt;BR /&gt;2 The SAS System 13:12 Tuesday, September 8, 2020&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;31 call execute ('%nrstr(catt('%split(SRC_DATASET=block.',memname,', OUT_PREFIX=_a, SPLIT_NUM=200, SPLIT_DEF=NOBS);'))');&lt;BR /&gt;____&lt;BR /&gt;180&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 20:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682411#M206557</guid>
      <dc:creator>edhuang</dc:creator>
      <dc:date>2020-09-08T20:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682444#M206566</link>
      <description>&lt;P&gt;&lt;SPAN&gt;1.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; If you have an easier way of splitting all of these datasets using data set, please share.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My point was: Why split?&amp;nbsp; Why not use options on the original data set? Like&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;proc whateveryouaredoinglater data=ORIGINALTABLE(firstobs=200 obs=400);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. This statement cannot work, the syntax is invalid&amp;nbsp;&lt;/SPAN&gt;for several reasons&lt;SPAN style="font-family: inherit;"&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier" size="2"&gt;call execute ('%nrstr(cat('%split(SRC_DATASET=block.',memname,', OUT_PREFIX=_a, SPLIT_NUM=200, SPLIT_DEF=NOBS)'))');&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Try the syntax I provided.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 23:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682444#M206566</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-08T23:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682447#M206567</link>
      <description>&lt;P&gt;How about dosubl?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set contents;
	rc=dosubl(cats('%split(SRC_DATASET=BLOCK.',MEMNAME,',out_prefix=BLOCK.',MEMNAME,',split_num=200,SPLIT_DEF=NOBS)'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 23:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682447#M206567</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-09-08T23:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682468#M206574</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; How about dosubl?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;There is no benefit here over call execute, and there is the overhead of starting new SAS threads.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 01:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682468#M206574</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-09T01:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682494#M206585</link>
      <description>&lt;P&gt;Hi Chris,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Believe it or not.&amp;nbsp; I tried&amp;nbsp;&lt;SPAN&gt;hhinohar's dosubl&amp;nbsp; It actually works.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Well, at least one thing is for sure after this, I need to read up on how to better use SAS macro.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help working through this.&amp;nbsp; My technique is ugly.&amp;nbsp; I wish it was more elegant.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 04:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682494#M206585</guid>
      <dc:creator>edhuang</dc:creator>
      <dc:date>2020-09-09T04:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682495#M206586</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;According to documentation it says,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"The DOSUBL function enables the immediate execution of SAS code after a text string is passed. The function imports macro variables from the calling environment, and macro variables that are created or updated during the execution of the submitted code are exported back to the calling environment."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"However, when you use a DATA step to set the value of a global macro variable, and then you use the CALL EXECUTE routine to call the macro, the DATA step code executes after the current DATA step completes. Example 1 demonstrates execution of the DATA step code."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p09dcftd1xxg1kn1brnjyc0q93yk.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p09dcftd1xxg1kn1brnjyc0q93yk.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I think this makes sense and I learned a lot from your SAS macro which is a great program!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 04:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682495#M206586</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-09-09T04:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through dataset library with macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682600#M206627</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/335263"&gt;@hhinohar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How about dosubl?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set contents;
	rc=dosubl(cats('%split(SRC_DATASET=BLOCK.',MEMNAME,',out_prefix=BLOCK.',MEMNAME,',split_num=200,SPLIT_DEF=NOBS)'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It does not matter if the macro runs after the data step so there is no reason to use DOSUBL() instead of CALL EXECUTE(), you are just wasting computer time.&amp;nbsp; But if the macro is complicated then you want it to run after the data step and not during the CALL EXECUTE() statement so wrap the %XXX inside of %NRSTR() so the macro call is pushed to run after the data step.&amp;nbsp; Not only will this eliminate timing issues it will also make your SAS log easier to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you do not want to run the macro for every variable in the dataset, just once for each dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=block._all_ noprint out=contents;
run;
data _null_;
  set contents;
  by memname;
  if first.memname;
  call execute(cats('%nrstr(%split)'
    ,'(SRC_DATASET=',catx('.',libname,memname)
    ,',out_prefix=',catx('.',libname,memname)
    ,',split_num=200,SPLIT_DEF=NOBS)'
  ));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Sep 2020 12:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-dataset-library-with-macro-function/m-p/682600#M206627</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-09T12:23:22Z</dc:date>
    </item>
  </channel>
</rss>

