<?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 help length exceeded in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722170#M223886</link>
    <description>Don't recreate a wheel.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/abc3c6ce1dbeedb84fe7f11da0603cda" target="_blank"&gt;https://gist.github.com/statgeek/abc3c6ce1dbeedb84fe7f11da0603cda&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sgf/2020/07/23/splitting-a-data-set-into-smaller-data-sets/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2020/07/23/splitting-a-data-set-into-smaller-data-sets/&lt;/A&gt;</description>
    <pubDate>Fri, 26 Feb 2021 15:17:37 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-02-26T15:17:37Z</dc:date>
    <item>
      <title>macro help length exceeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722080#M223864</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am getting an error due to the number of files that I need to split. The macro worked fine with &amp;lt;100 obs.&lt;/P&gt;
&lt;P&gt;53 DATA DK_PANDE2_SME;&lt;BR /&gt;54 set DK_Pande END=EOT;&lt;BR /&gt;55 RECNUM = STRIP(PUT(_n_, BEST.));&lt;BR /&gt;56 IF EOT THEN DO;&lt;BR /&gt;57 CALL SYMPUTX( 'nobs', RECNUM);&lt;BR /&gt;58 END;&lt;BR /&gt;59 run;&lt;/P&gt;
&lt;P&gt;NOTE: There were 17217 observations read from the data set WORK.DK_PANDE.&lt;BR /&gt;NOTE: The data set WORK.DK_PANDE2_SME has 17217 observations and 12 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 5.62 seconds&lt;BR /&gt;cpu time 5.56 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;nobs;&lt;BR /&gt;17217&lt;BR /&gt;62 &lt;BR /&gt;63 proc datasets library=output kill;&lt;BR /&gt;NOTE: Deleting OUTPUT.ADDRESSHISTORY (memtype=DATA).&lt;BR /&gt;64 run;&lt;/P&gt;
&lt;P&gt;65 quit;&lt;/P&gt;
&lt;P&gt;NOTE: PROCEDURE DATASETS used (Total process time):&lt;BR /&gt;real time 0.04 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;66 &lt;BR /&gt;67 %macro split (SRC_DATASET=, OUT_PREFIX=, SPLIT_NUM=, SPLIT_DEF=);&lt;BR /&gt;68 /* Parameters:&lt;BR /&gt;69 /* SRC_DATASET - name of the source data set */&lt;BR /&gt;70 /* OUT_PREFIX - prefix of the output data sets */&lt;BR /&gt;71 /* SPLIT_NUM - split number */&lt;BR /&gt;72 /* SPLIT_DEF - split definition (=SETS or =NOBS) */&lt;BR /&gt;73 &lt;BR /&gt;74 %local I K S TLIST;&lt;BR /&gt;75 &lt;BR /&gt;76 /* number of observations &amp;amp;K, number of smaller datasets &amp;amp;S */&lt;BR /&gt;77 data _null_;&lt;BR /&gt;78 if 0 then set &amp;amp;SRC_DATASET nobs=N;&lt;BR /&gt;79 if upcase("&amp;amp;SPLIT_DEF")='NOBS' then&lt;BR /&gt;80 do;&lt;BR /&gt;81 call symputx('K',&amp;amp;SPLIT_NUM);&lt;BR /&gt;82 call symputx('S',ceil(N/&amp;amp;SPLIT_NUM));&lt;BR /&gt;83 put "***MACRO SPLIT: Splitting into datasets of no more than &amp;amp;SPLIT_NUM observations";&lt;BR /&gt;84 end;&lt;BR /&gt;85 else if upcase("&amp;amp;SPLIT_DEF")='SETS' then&lt;BR /&gt;86 do;&lt;BR /&gt;87 call symputx('S',&amp;amp;SPLIT_NUM);&lt;BR /&gt;88 call symputx('K',ceil(N/&amp;amp;SPLIT_NUM));&lt;BR /&gt;89 put "***MACRO SPLIT: Splitting into &amp;amp;SPLIT_NUM datasets";&lt;BR /&gt;90 end;&lt;BR /&gt;91 else put "***MACRO SPLIT: Incorrect SPLIT_DEF=&amp;amp;SPLIT_DEF value. Must be either SETS or NOBS.";&lt;BR /&gt;3 The SAS System 09:23 Friday, February 26, 2021&lt;/P&gt;
&lt;P&gt;92 stop;&lt;BR /&gt;93 run;&lt;BR /&gt;94 &lt;BR /&gt;95 /* terminate macro if nothing to split */&lt;BR /&gt;96 %if (&amp;amp;K le 0) or (&amp;amp;S le 0) %then %return;&lt;BR /&gt;97 &lt;BR /&gt;98 /* generate list of smaller dataset names */&lt;BR /&gt;99 %do I=1 %to &amp;amp;S;&lt;BR /&gt;100 %let TLIST = &amp;amp;TLIST &amp;amp;OUT_PREFIX._&amp;amp;I;&lt;BR /&gt;101 %end;&lt;BR /&gt;102 &lt;BR /&gt;103 /* split source dataset into smaller datasets */&lt;BR /&gt;104 data &amp;amp;TLIST;&lt;BR /&gt;105 set &amp;amp;SRC_DATASET;&lt;BR /&gt;106 select;&lt;BR /&gt;107 %do I=1 %to &amp;amp;S;&lt;BR /&gt;108 when(_n_ &amp;lt;= &amp;amp;K * &amp;amp;I) output &amp;amp;OUT_PREFIX._&amp;amp;I;&lt;BR /&gt;109 %end;&lt;BR /&gt;110 end;&lt;BR /&gt;111 run;&lt;BR /&gt;112 &lt;BR /&gt;113 %mend split;&lt;BR /&gt;114 &lt;BR /&gt;115 &lt;BR /&gt;116 %split(SRC_DATASET=WORK.DK_PANDE2_SME, OUT_PREFIX=WORK.DK_PANDE3_SME, SPLIT_NUM=1, SPLIT_DEF=NOBS);&lt;/P&gt;
&lt;P&gt;***MACRO SPLIT: Splitting into datasets of no more than 1 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.01 seconds&lt;/P&gt;
&lt;P&gt;ERROR: The text expression length (65540) exceeds maximum length (65534). The text expression has been truncated to 65534 &lt;BR /&gt;characters.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 09:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722080#M223864</guid>
      <dc:creator>Kiteulf</dc:creator>
      <dc:date>2021-02-26T09:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: macro help length exceeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722086#M223866</link>
      <description>&lt;P&gt;In about 99 % of cases, splitting a dataset is not needed, solves no purpose, makes further processing harder, and is therefore an exercise in stupidity.&lt;/P&gt;
&lt;P&gt;And in your particular case, there is NOTHING gained by putting each observation into its own dataset. You can always restrict any procedure or data step with WHERE conditions, and you can use BY processing to do an action for subsets of the dataset, all in one step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Saving large data into macro variables is not possible, as they are restricted to a length of 65534 (as you have seen). Always store &lt;EM&gt;data&lt;/EM&gt; in &lt;EM&gt;data&lt;/EM&gt;sets, that's where it belongs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, what are you trying to achieve with this at all?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 10:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722086#M223866</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-26T10:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: macro help length exceeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722170#M223886</link>
      <description>Don't recreate a wheel.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/abc3c6ce1dbeedb84fe7f11da0603cda" target="_blank"&gt;https://gist.github.com/statgeek/abc3c6ce1dbeedb84fe7f11da0603cda&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sgf/2020/07/23/splitting-a-data-set-into-smaller-data-sets/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2020/07/23/splitting-a-data-set-into-smaller-data-sets/&lt;/A&gt;</description>
      <pubDate>Fri, 26 Feb 2021 15:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722170#M223886</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-26T15:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: macro help length exceeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722173#M223889</link>
      <description>&lt;P&gt;While I agree with everything that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;said, you might need to appreciate the magnitude of the problem.&amp;nbsp; This is not a simple case where you need a few extra characters to fit.&amp;nbsp; Consider what happens when you use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let TLIST = &amp;amp;TLIST &amp;amp;OUT_PREFIX._&amp;amp;I;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That's clearly the point where you overwhelm the length of a macro variable.&amp;nbsp; Suppose you cut it down as short as possible:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let TLIST = &amp;amp;TLIST _&amp;amp;I;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After all, you could always add the prefix back in later.&amp;nbsp; However, even in this case where you only add _&amp;amp;I, and even in the narrow range of looping from 1000 to 9999, the length of &amp;amp;TLIST comes out to 53,999.&amp;nbsp; Clearly, this program will not be feasible using your current approach when you have so many files.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 15:21:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722173#M223889</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-02-26T15:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: macro help length exceeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722253#M223923</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35213"&gt;@Kiteulf&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also would strongly prefer &lt;EM&gt;one&lt;/EM&gt; &lt;SPAN&gt;&lt;EM&gt;17217&lt;/EM&gt;-observations dataset to&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;EM&gt;17217&lt;/EM&gt; &lt;EM&gt;one&lt;/EM&gt;-observation datasets. But if this is really what you want and the macro approach fails, then use a different approach.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For example, create ODS OUTPUT datasets from PROC REPORT:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _tmp / view=_tmp;
set DK_PANDE2_SME;
_seqno=_n_;
run;

ods select none;
ods noresults;
options nonotes;
ods output report(match_all)=DK_PANDE3_SME_1(drop=_seqno _break_);
proc report data=_tmp;
by _seqno;
run;
ods select all;
ods results;
options notes;

proc delete data=_tmp (mt=view);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Datasets &lt;FONT face="courier new,courier"&gt;DK_PANDE3_SME_1-DK_PANDE3_SME_17217 &lt;/FONT&gt;will contain the 1st, ..., 17217th observation of dataset&amp;nbsp;&lt;FONT face="courier new,courier"&gt;DK_PANDE2_SME&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 20:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722253#M223923</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-26T20:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: macro help length exceeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722355#M223967</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp; and everybody else;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I took the macro I had and split into approx 100 in each data set, then I could split each of those datasets into 1 obs per dataset through looping through the 100 dataset (another macro). Works very well!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason I had to have 1 obs per dataset is that the xml in each obs is about 200 000 char long. So instead of opening the file everytime in a subsequent macro I can pick up just one observation/dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Time spent per operation fell with a factor of 30 &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 19:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722355#M223967</guid>
      <dc:creator>Kiteulf</dc:creator>
      <dc:date>2021-02-27T19:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: macro help length exceeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722368#M223971</link>
      <description>&lt;P&gt;There is no reason to try to create the monster macro variable.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do I=1 %to &amp;amp;S;
  %let TLIST = &amp;amp;TLIST &amp;amp;OUT_PREFIX._&amp;amp;I;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead just expand the individual macro variables where you need them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data 
%do I=1 %to &amp;amp;S;
 &amp;amp;TLIST &amp;amp;OUT_PREFIX._&amp;amp;I
%end;
;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Feb 2021 22:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-help-length-exceeded/m-p/722368#M223971</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-27T22:26:21Z</dc:date>
    </item>
  </channel>
</rss>

