<?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 length of the value of the macro variable exceeds maximum length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-length-of-the-value-of-the-macro-variable-exceeds-maximum/m-p/539046#M148453</link>
    <description>Data belongs in datasets, not in macro variables.&lt;BR /&gt;You can create a format for your ~20000 values, or read them into a hash object, if you want to avoid a simple sub-select.&lt;BR /&gt;Mind that there may be other reasons for the bad performance of your sub-select attempt.</description>
    <pubDate>Wed, 27 Feb 2019 16:53:41 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-02-27T16:53:41Z</dc:date>
    <item>
      <title>Macro length of the value of the macro variable exceeds maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-length-of-the-value-of-the-macro-variable-exceeds-maximum/m-p/539042#M148451</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of 17,888 unique ids (IDVAR) from a very large dataset (HAVE1) that I would like to split into several macro variables. I'd like to query based on these unique ids in another very large dataset (HAVE2). I define "large dataset" as having over 200 millions rows. Creating a sub-query would take hours to run which is why I'm creating the macro. I've used the code below when I have fewer unique IDs, which runs beautifully. But now I run into the issue of exceed the maximum macro limit.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL NOPRINT;
	SELECT DISTINCT QUOTE(TRIM(idvar))
		INTO :LIST1 SEPARATED BY ","
			FROM have1;
QUIT;

%PUT LIST1= &amp;amp;LIST1;


PROC SQL;
	CREATE TABLE want AS 
		SELECT DISTINCT *,
				FROM have2
					WHERE  idvar IN (&amp;amp;LIST1);
QUIT;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attempted to use the below code, but I run into issues where the unique IDs get cut-off and additional wording gets input to the list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let n_per_list=4000 ;

data _null_;
  length idlist $32000;
  length macrolist $1000;
  retain macrolist;
  do i=1 to &amp;amp;n_per_list until (eof);
    set HAVE1 end=eof;
    idlist=catx(',',idlist,QUOTE(TRIM(IDVAR)));
  end;
  listno+1;
  call symputx(cats('paralist',listno),idlist);
  macrolist=catx(',',macrolist,cats('&amp;amp;','paralist',listno));
  call symputx('paralist',macrolist);
run;

%put Paralist=%superq(ParaList);
Paralist=&amp;amp;paralist1,&amp;amp;paralist2,&amp;amp;paralist3,&amp;amp;paralist4,&amp;amp;paralist5
%put &amp;amp;=Paralist;


&lt;/PRE&gt;&lt;P&gt;Any assistance that explains how I can properly split up a long list of IDs into several macro variables, will be much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 16:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-length-of-the-value-of-the-macro-variable-exceeds-maximum/m-p/539042#M148451</guid>
      <dc:creator>glcoolj12</dc:creator>
      <dc:date>2019-02-27T16:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Macro length of the value of the macro variable exceeds maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-length-of-the-value-of-the-macro-variable-exceeds-maximum/m-p/539046#M148453</link>
      <description>Data belongs in datasets, not in macro variables.&lt;BR /&gt;You can create a format for your ~20000 values, or read them into a hash object, if you want to avoid a simple sub-select.&lt;BR /&gt;Mind that there may be other reasons for the bad performance of your sub-select attempt.</description>
      <pubDate>Wed, 27 Feb 2019 16:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-length-of-the-value-of-the-macro-variable-exceeds-maximum/m-p/539046#M148453</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-27T16:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro length of the value of the macro variable exceeds maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-length-of-the-value-of-the-macro-variable-exceeds-maximum/m-p/539047#M148454</link>
      <description>&lt;P&gt;Just add a test of the length in the DO loop.&lt;/P&gt;
&lt;P&gt;Here is example using names from SASHELP.CLASS and stopping with each individual list is more than 20 characters long.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1 ;
 set sashelp.class ;
 rename name=idvar;
run;
data _null_;
  length idlist $32000;
  length macrolist $32000;
  retain macrolist;
  do i=1 by 1 until (eof or length(idlist)&amp;gt;20);
    set have1 end=eof;
    idlist=catx(',',idlist,QUOTE(TRIM(IDVAR)));
  end;
  listno+1;
  call symputx(cats('paralist',listno),idlist);
  macrolist=catx(',',macrolist,cats('&amp;amp;','paralist',listno));
  if eof then call symputx('paralist',macrolist);
run;

%put paralist = %superq(paralist);
%put &amp;amp;=paralist;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;39    %put paralist = %superq(paralist);
paralist = &amp;amp;paralist1,&amp;amp;paralist2,&amp;amp;paralist3,&amp;amp;paralist4,&amp;amp;paralist5,&amp;amp;paralist6,&amp;amp;paralist7
40    %put &amp;amp;=paralist;
PARALIST="Alfred","Alice","Barbara","Carol","Henry","James","Jane","Janet","Jeffrey","John","Joyce","Judy",
"Louise","Mary","Philip","Robert","Ronald","Thomas","William"
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 16:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-length-of-the-value-of-the-macro-variable-exceeds-maximum/m-p/539047#M148454</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-27T16:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro length of the value of the macro variable exceeds maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-length-of-the-value-of-the-macro-variable-exceeds-maximum/m-p/539091#M148468</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132054"&gt;@glcoolj12&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A join would normally be much faster. You could try this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
	create table want as
		select have2.* 
		from have2 inner join have1
		on have2.idvar = have1.idvar;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it is still too slow, it might be a good idea to create an index on have2, but the outcome is difficult to predict.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 19:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-length-of-the-value-of-the-macro-variable-exceeds-maximum/m-p/539091#M148468</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-02-27T19:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro length of the value of the macro variable exceeds maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-length-of-the-value-of-the-macro-variable-exceeds-maximum/m-p/539221#M148536</link>
      <description>&lt;P&gt;In general, macro is orders of magnitude slower than data step, SQL, or RDBMS joins.&amp;nbsp; Especially if you're writing huge amounts of data to the macro symbol table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since your data is already in a dataset or table, just use it from there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following on from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt;&amp;nbsp;'s post, I ran the below code as a simple test to see which would run faster:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   do x=1 to 1E7;
      random=ranuni(0);
      output;
   end;
run;

data list;
   do y=1 to 1E8 by 3;
      random=ranuni(0);
      output;
   end;
run;

proc sort data=have;
   by random;
run;
proc sort data=list;
   by random;
run;

%bench(start) 
proc sql _method;
   create table want1 as
   select x
   from   have
   where  x in (
      select y from list
   )
   order by x;
quit;
%bench(end)

%bench(start) 
proc sql _method;
   create table want2 as
   select x
   from   have
   join   list
   on     have.x=list.y
   order by x;
quit;
%bench(end)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;want1:&amp;nbsp;&amp;nbsp;Total time: 00 hours, 02 minutes, 08 seconds 127.50099992752&lt;/P&gt;&lt;P&gt;want2:&amp;nbsp;&amp;nbsp;Total time: 00 hours, 00 minutes, 41 seconds 41.3870000839233&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SQL execution methods:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;want1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;      sqxcrta
          sqxsort
              sqxfil
                  sqxsrc( WORK.HAVE )

NOTE: SQL subquery execution methods chosen are:

          sqxsubq
              sqxsrc( WORK.LIST )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;want2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because the data was so narrow and would fit in memory, SQL used a hash join:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: SQL execution methods chosen are:

      sqxcrta
          sqxsort
              sqxjhsh
                  sqxsrc( WORK.LIST )
                  sqxsrc( WORK.HAVE )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 06:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-length-of-the-value-of-the-macro-variable-exceeds-maximum/m-p/539221#M148536</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-02-28T06:17:51Z</dc:date>
    </item>
  </channel>
</rss>

