<?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: How to create a macro variable which exceeds length of 65535 to query DB with PassThru? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832403#M329010</link>
    <description>&lt;P&gt;You type it into the code you are using to generate the code.&amp;nbsp; Note that you could have the code generate a reference to a macro variable ('... from &amp;amp;tablename .... ') and set the value into the macro variable (%let tablename=myschema.mydbtable;) before including the generated code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What ever method works for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values of the variable never have actual quotes you can skip the QUOTE function and just write the opening an closing quotes as part of the PUT statement.&amp;nbsp; Make sure to backup over the trailing space that PUT will add after it writes a variable's value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   file code ;
   set list end=eof;
   if _n_=1 then put
 'create table want as'
/'select * from connection to oracle'
/'( select * from myschema.mydbtable where myvar in'
/'(' @
   ;
   else put ',' @;
   put "'" value +(-1) "'" ;
  if eof then put 
 ')'
/');'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Sep 2022 20:11:51 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-09-08T20:11:51Z</dc:date>
    <item>
      <title>How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832176#M328905</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I have hashed account numbers that I am querying against a database. I cannot accommodate the length of a macro. Could you please help me with that?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used the following code to generate a sample dataset. This is dummy data. I am attaching error that I am getting while running the code.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data ValList (drop=ValueList);
do ValueList = 100 to 1000000 by 100;
valuenum=put(ValueList,6.);
output;
end;
run;

/*method1*/

proc sql noprint;
select "'"||strip(Valuenum)||"'" into :SearchMacro separated by ', ' from ValList;
quit;

/* method2*/

%macro test;                                                                                                                            
  %let dsid=%sysfunc(open(ValList));                                                                                                         
  %let cnt=%sysfunc(attrn(&amp;amp;dsid,nobs));                                                                                                  
    %do i=1 %to &amp;amp;cnt;                                                                                                                     
      %let rc=%sysfunc(fetchobs(&amp;amp;dsid,&amp;amp;i));                                                                                               
      %cmpres(%sysfunc(getvarc(&amp;amp;dsid,%sysfunc(varnum(&amp;amp;dsid,Valuenum)))))                                                                       
    %end;                                                                                                                                 
  %let rc=%sysfunc(close(&amp;amp;dsid));                                                                                                        
%mend test;                                                                                                                             
       
                                                                                                                                
%put %test;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The second method was copied from&amp;nbsp;&lt;BR /&gt;&lt;A title="Sample 39605: Create a string that goes beyond the 64K limit for macro variables" href="https://support.sas.com/kb/39/605.html" target="_self"&gt;https://support.sas.com/kb/39/605.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works well for the shorter numbers (for a macro), but I don't know how to give quotes and commas to separate from one number to the other. Any help with that code is much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Buddha.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 18:01:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832176#M328905</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-09-07T18:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832180#M328909</link>
      <description>&lt;P&gt;I think you are referring to a macro&amp;nbsp;&lt;EM&gt;variable&lt;/EM&gt; that is too long, and not a macro. If so, please change the subject line in your original message to reflect that change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please do not attach files. Many of us will not download attached files. I cannot see the error you have in an attachment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please do not show us the log in non-monospaced fonts. Instead, copy the log as text and then paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Insert Log Icon in SAS Communities.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66171iFEC370B1DBF07B28/image-size/large?v=v2&amp;amp;px=999" role="button" title="Insert Log Icon in SAS Communities.png" alt="Insert Log Icon in SAS Communities.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, if you are getting a macro variable that is too long, you can get around this via creating code using CALL EXECUTE or perhaps via the method in your link.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 17:16:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832180#M328909</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-07T17:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832183#M328910</link>
      <description>&lt;P&gt;Why do you want to put that much text into a macro variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That limit to the size of macro variables is in the documentation. Not really going to get around it much. If you say what you are actually attempting to do there are likely much better ways to accomplish the task.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 17:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832183#M328910</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-07T17:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832189#M328912</link>
      <description>&lt;P&gt;If you want to add quotes and commas, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;i. &amp;gt; 1 %then ,;
"%cmpres(%sysfunc(getvarc(&amp;amp;dsid,%sysfunc(varnum(&amp;amp;dsid,Valuenum)))))"&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Sep 2022 17:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832189#M328912</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-07T17:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832200#M328915</link>
      <description>&lt;P&gt;There are ways to generate code that is longer then 65k bytes, but that might just hit a different limit imposed by the database you are trying to query.&amp;nbsp; The best answer is to upload the list to the database and do the query there.&amp;nbsp; Check with the DBA for the database how you can create temporary tables in the database you can use to store the list of values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are ways to generate longer strings.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Nested macro variable references.&amp;nbsp; Set a series of shorter macro variables, let's call them MVAR1, MVAR2, ... and then set SEARCHMACRO to the string &amp;amp;mvar1,&amp;amp;mvar2,.... so that when you evaluate &amp;amp;SEARCHMACRO all of the nested macro variables are evaluated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length str $32767 ;
  set vallist end=eof;
  retain n str;
  str = catx(',',str,quote(trim(valuenum),"'"));
  if (eof or (length(str) &amp;gt; 32500)) then do;
    n+1;
    call symputx(cats('mvar',n),str);
    str=' ';
  end;
  if eof then do;
    do n=1 to n;
      str=catx(',',str,cats('&amp;amp;mvar',n));
    end;
    call symputx('searchmacro',str);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) Write the code to a FILE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
   file code ;
  set vallist;
  if _n_=1 then put put 'select * from mytable where id in ('  @;
  else put ',' @;
  str = quote(trim(valuenum),"'");
  put str ;
  if eof then put ');';
run;
proc sql;
%include code ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3) Variation on (2) only using CALL EXECUTE() instead of actually writing a file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS&amp;nbsp; Do not use STRIP() before quoting the value of a character variable.&amp;nbsp; That will remove leading spaces and result in quoted strings that will NOT match the original values.&amp;nbsp; Just use TRIM() as the trailing spaces are ignored by SAS string comparisons.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 18:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832200#M328915</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-07T18:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832302#M328957</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;, but the first option you present still falls into the length-restriction-trap, right?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 13:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832302#M328957</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-09-08T13:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832308#M328958</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;, but the first option you present still falls into the length-restriction-trap, right?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No.&amp;nbsp; Each macro variable will be shorter than 32K bytes.&amp;nbsp; And unless you have millions of items in the list the macro variable with the list of references to the other macro variables will be very short.&amp;nbsp; So if you needed 320K bytes to expand the whole list of codes then you would make 11 macro variables. 10 that are 32K each and one that is at most 100 bytes long.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Demo:&lt;/P&gt;
&lt;PRE&gt;844  data _null_;
845    call symputx('mvar1','a,b,c');
846    call symputx('mvar2','d,e,f');
847    call symputx('list','&amp;amp;mvar1,&amp;amp;mvar2');
848  run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


849  %put LIST = %superq(list);
LIST = &amp;amp;mvar1,&amp;amp;mvar2
850  %put LIST = &amp;amp;list;
LIST = a,b,c,d,e,f
&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Sep 2022 13:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832308#M328958</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-08T13:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832312#M328960</link>
      <description>&lt;P&gt;Ok, understood. Nice&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your second code for me to work requires some ammendment. There is a typo error with 2 put statements and I think end=eof is missing as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data ValList (drop=ValueList);
do ValueList = 100 to 1000000 by 100;
valuenum=put(ValueList,6.);
id=valuenum;
output;
end;
run;

filename code temp;
data _null_;
  file code ;
  set vallist end=eof;
  length str $32767 ;
  if _n_=1 then put 'create table oks as select * from vallist where id in ('  @;
  else put ' ' @;
  str = quote(trim(valuenum));
  put str ;
  if eof then put ');';
run;

proc sql;
%include code ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Sep 2022 13:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832312#M328960</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-09-08T13:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832318#M328962</link>
      <description>&lt;P&gt;You will need to flesh out the full SQL statement (or more) that you want to generate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to see that code you generated you can do some combination of:&lt;BR /&gt;1) Just use FILE LOG instead of making an actual file to debug the code generation.&lt;/P&gt;
&lt;P&gt;2) Read the file back in and dump it to the log.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile code;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3) Add the / SOURCE2 option to the %INCLUDE statement so the code is included in the log when it runs.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 14:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832318#M328962</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-08T14:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832370#M328989</link>
      <description>&lt;P&gt;Tom, the code works, but I have couple of questions&lt;BR /&gt;1. How could I use this to query against a DB? Incase of regular macro variable, I could use&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where Valuenum (column name) in (&amp;amp;Valuenum.).&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. When I use&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;infile code;&lt;BR /&gt;input;&lt;BR /&gt;put _infile_;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the above I get the values in double quotes, but leading spaces are there and commas are missing as shown below.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Valuenum.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75076i5ECB937771634955/image-size/large?v=v2&amp;amp;px=999" role="button" title="Valuenum.PNG" alt="Valuenum.PNG" /&gt;&lt;/span&gt;&amp;nbsp;Thanks for helping me&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 17:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832370#M328989</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-09-08T17:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832375#M328993</link>
      <description>&lt;P&gt;The leading spaces are there because you put them into your test data by using the PUT() function without either using the LEFT() function to remove them or the -L format modifier to left align the generated strings.&amp;nbsp; To fix this make sure the set of values you have in the dataset match the values you want to find in the remote database.&amp;nbsp; You could possibly remove them in the process of generating the code, but that would just mask the original mistake of including them in the first place in the dataset with the list of values to find.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you used the code I provided that passed the QUOTE() function the second argument then the values would be quoted with single quotes instead of double quotes.&amp;nbsp; Try it yourself:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set sashelp.class (obs=3);
  length str1 str2 $20 ;
  str1=quote(trim(name));
  str2=quote(trim(name),"'");
run;

proc print;
 var name str1 str2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs     Name        str1         str2

 1     Alfred     "Alfred"     'Alfred'
 2     Alice      "Alice"      'Alice'
 3     Barbara    "Barbara"    'Barbara'
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to generate a pass thru SQL statement then do that.&amp;nbsp; Sounds like you might want to generate this type of statement you could run in PROC SQL.&amp;nbsp; Here ORACLE is the name of the connection you created with the CONNECT statement in the PROC SQL step.&amp;nbsp; WANT is the name of the SAS dataset you want to create.&amp;nbsp; &amp;nbsp;MYSCHEMA.MYDBTABLE is the name of the table in the remote database you are querying.&amp;nbsp; MYVAR is the name of the variable in that table that you are using to filter on.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table want as 
select * from connection to oracle 
( select * from myschema.mydbtable where myvar in 
('001'
,'002'
,....
)
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Sep 2022 18:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832375#M328993</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-08T18:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832399#M329008</link>
      <description>&lt;P&gt;The premise of Tom's solution is that you can generate the full query to a text file and then %include that code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a fully worked example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*list of ages to choose from;
data ageSelected;
input Age;
cards;
10
13
15
;;;;
run;

*create macro variable;
proc sql;
select age into :ageList separated by ", " from AgeSelected;
quit;

*query with macro variable pass to the WHERE statement;
proc sql;
create table want as
select * from sashelp.class
where age in (&amp;amp;ageList);
quit;


data _null_;

*input data set is the subset list;
*EOF tells SAS which is the last record of the file;
set ageSelected end = eof ;

*create text file to store code;
file '/home/fkhurshed/Demo1/query.sas';

*put main portion of the query, excluding list of values;
if _n_ =1 then do;
put  'proc sql; create table want as select * from sashelp.class where age in(';
end;

*ouput list of values;
put age;
*output comma except for last record;
if not eof then put ', ';

*if last record end the query;
if eof then put '); quit;';

run;

*run the query - probably a good idea to open first and verify the query is correct;
%include '/home/fkhurshed/Demo1/query.sas';&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Sep 2022 19:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832399#M329008</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-08T19:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832400#M329009</link>
      <description>&lt;P&gt;Thank Tom for that explanation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I give myvar (column name) for macro variable with your code for DB?&lt;/P&gt;&lt;P&gt;Could you please comment on that?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;create table want as&lt;BR /&gt;select * from connection to oracle&lt;BR /&gt;( select * from myschema.mydbtable where&lt;STRONG&gt; myvar&lt;/STRONG&gt; in&lt;BR /&gt;('001'&lt;BR /&gt;,'002'&lt;BR /&gt;,....&lt;BR /&gt;)&lt;BR /&gt;);&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 19:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832400#M329009</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-09-08T19:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832403#M329010</link>
      <description>&lt;P&gt;You type it into the code you are using to generate the code.&amp;nbsp; Note that you could have the code generate a reference to a macro variable ('... from &amp;amp;tablename .... ') and set the value into the macro variable (%let tablename=myschema.mydbtable;) before including the generated code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What ever method works for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values of the variable never have actual quotes you can skip the QUOTE function and just write the opening an closing quotes as part of the PUT statement.&amp;nbsp; Make sure to backup over the trailing space that PUT will add after it writes a variable's value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   file code ;
   set list end=eof;
   if _n_=1 then put
 'create table want as'
/'select * from connection to oracle'
/'( select * from myschema.mydbtable where myvar in'
/'(' @
   ;
   else put ',' @;
   put "'" value +(-1) "'" ;
  if eof then put 
 ')'
/');'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 20:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832403#M329010</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-08T20:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832408#M329011</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;

*input data set is the subset list;
*EOF tells SAS which is the last record of the file;
set valueList end = eof ;

*put main portion of the query, excluding list of values;
if _n_ =1 then do;
call execute(  'proc sql; create table want as
select * from connection to oracle
( select * from myschema.mydbtable where myvar in
(');
end;

*ouput list of values;
call execute(quote(put(ValueList, 6. -l)));
*output comma except for last record;
if not eof then call execute(', ');

*if last record end the query;
if eof then call execute( ')); quit;');

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another option above - may need to check the brackets at the end.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 08 Sep 2022 20:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832408#M329011</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-08T20:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832720#M329154</link>
      <description>&lt;P&gt;The "traditional" way for doing this once your filter table reaches a certain size is:&lt;/P&gt;
&lt;P&gt;1. upload your filter table into the database (eventually as a temporary table)&lt;/P&gt;
&lt;P&gt;2. inner join that executes fully in-database&lt;/P&gt;
&lt;P&gt;3. load result-set back to SAS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Above required of course that you are allowed to write to the database as well as create and drop tables in at least the temp space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to stick with the macro variable then what I've seen done in the past is the use of some "sqlpump" macro that splits-up your query into junks (one junk below 32KB) and then combines the result sets in SAS (Proc Append). This requires of course some SAS macro coding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 04:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832720#M329154</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-09-11T04:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832794#M329200</link>
      <description>&lt;P&gt;Hi Tom, Sorry for the delayed response. The code is running without errors with your sample code, but it is not generating any table to look at the data. Could you help me with that please?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran the below code, but I didn't get any want table created.&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;file code ;&lt;BR /&gt;set list end=eof;&lt;BR /&gt;if _n_=1 then put&lt;BR /&gt;'create table want as'&lt;BR /&gt;/'select * from connection to oracle'&lt;BR /&gt;/'( select * from myschema.mydbtable where myvar in'&lt;BR /&gt;/'(' @&lt;BR /&gt;;&lt;BR /&gt;else put ',' @;&lt;BR /&gt;put "'" value +(-1) "'" ;&lt;BR /&gt;if eof then put&lt;BR /&gt;')'&lt;BR /&gt;/');'&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Buddha.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 23:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832794#M329200</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-09-11T23:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832795#M329201</link>
      <description>&lt;P&gt;You create a file with code in it. To execute the code, you need to %INCLUDE the file in an appropriate location (as you create SQL code, it must be included in a PROC SQL).&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 23:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832795#M329201</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-11T23:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832796#M329202</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Thanks for the suggestions. The environment that I am using doesn't allow me to create temporary table to query against the table.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 23:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832796#M329202</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-09-11T23:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable which exceeds length of 65535 to query DB with PassThru?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832799#M329204</link>
      <description>&lt;P&gt;Hi Kurt,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;When I am using pass-thru and where statement with field_name in (%include code;) , SAS is throwing error and that statement cannot be valid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 00:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-which-exceeds-length-of-65535-to/m-p/832799#M329204</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-09-12T00:53:53Z</dc:date>
    </item>
  </channel>
</rss>

