<?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: call symput within data _null_: multiple iterations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230196#M41732</link>
    <description>&lt;P&gt;You can use CALL EXECUTE to generate code that will sit on a stack and execute AFTER the data step stops.&lt;/P&gt;
&lt;P&gt;So your DATA step should look something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set test.TABLES;  
   call execute(cats('%nrstr(%readOneFile)'
    ,'(lib=source,table_in=',name_dataset
    ,',table_out=temp_table)'
    ));
   call execute('PROC APPEND BASE=&amp;amp;table_master(compress=yes) DATA=temp_table force; RUN;');
run;

%delete_table(table=temp_table);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 Oct 2015 23:33:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2015-10-15T23:33:30Z</dc:date>
    <item>
      <title>call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230051#M41695</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset "TABLES" which contains 100 rows and only 1 variable "name_dataset".&lt;/P&gt;
&lt;P&gt;Each row contains the name of another&amp;nbsp;SAS dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to write a procedure which&lt;/P&gt;
&lt;P&gt;- reads those 100 rows one by one, (read the name of the SAS dataset)&lt;/P&gt;
&lt;P&gt;- via a macro, reads each dataset (one by one), do some modifications, and append the results to a master table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seems easy, but I'm a little bit stuck here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought that with the code below, it would do 100&amp;nbsp;&lt;STRONG&gt;iterations&lt;/STRONG&gt; and at&amp;nbsp;each iteration it would&amp;nbsp;save the name of the dataset of the current&amp;nbsp;iteration into a macrovariable and executes the macro that follows.(readOneFile).&amp;nbsp; But what it does, it takes only the last value (row 100) and only executes 1 time the macro.&amp;nbsp; So it's only 1 iteration if I understand well.&amp;nbsp; Does anybody knows in what way I have to modify my code so that i actually does 100 times the same, but each time with another dataset/table?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the code I have so far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;FONT color="#000080"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt; readAllFiles(table_master=); &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;...&amp;nbsp;some code, which works well ...&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; set test.TABLES;&amp;nbsp; /* TABLES contains 100 observations and&amp;nbsp;only 1 field 'name_dataset' */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; call symput (&lt;FONT color="#800080"&gt;&lt;FONT color="#800080"&gt;&lt;FONT color="#800080"&gt;'name_dataset'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;, name_dataset);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;%&lt;STRONG&gt;&lt;I&gt;readOneFile&lt;/I&gt;&lt;/STRONG&gt;(lib=source,table_in=&amp;amp;name_dataset, table_out=temp_table)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROC APPEND BASE=&amp;amp;table_master(compress=yes) DATA=temp_table force;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RUN;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %&lt;STRONG&gt;&lt;I&gt;delete_table&lt;/I&gt;&lt;/STRONG&gt;(table=temp_table);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;%mend;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;%macro ReadOneFile (lib=,table_in=,table_out=);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;...&amp;nbsp;some code, which works well ...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;%mend;&lt;/FONT&gt;&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>Thu, 15 Oct 2015 11:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230051#M41695</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2015-10-15T11:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230054#M41697</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;%macro ReadOneFile (lib=,table_in=,table_out=);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;...&amp;nbsp;some code, which works well ...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;%mend;&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since you have specifically avoided telling us what is in this macro, we have to speculate, which is never a good thing. But regardless, my speculation is that you cannot include this macro inside a data _null_; data step, because only data step code can appear inside a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The general outline of what you need to do is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro readAllFiles(table_master=);
%do ii=1 %to 100;
    data _null_;
        set test.tables(obs=&amp;amp;ii firstobs=&amp;amp;ii);
        call symputx('name_dataset',name_dataset);
    run;
    %readOneFile(lib=source,table_in=&amp;amp;name_dataset,table_out=temp_table)
    proc append ...
    run; 
    %delete_table(table=temp_table)
%end;
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 11:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230054#M41697</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-15T11:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230058#M41699</link>
      <description>&lt;P&gt;Hi PaigeMiller,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you very much,&amp;nbsp; this is what I was looking for.&lt;/P&gt;
&lt;P&gt;Sorry for not including all the code, I thought I wrote down all the relevant code for explaining my problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;(in the second macro, there were some procs involved, such as import, sort, sql)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what I learned is that in a datastep, you can not make a reference to a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought I could avoid using a DO-loop because the data _null_ step would iterate all records just till the last record.&amp;nbsp; But that's also not the case.&lt;/P&gt;
&lt;P&gt;If I have a table with a variable number of rows instead of 100 rows, is there a short way to replace&amp;nbsp; " %do ii = 1 %to 100;&amp;nbsp; " ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do I have to use a proc SQL (with a count)&amp;nbsp;to determine the number of rows before the do loop?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 12:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230058#M41699</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2015-10-15T12:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230063#M41702</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28934"&gt;@fre&lt;/a&gt; wrote:&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;So what I learned is that in a datastep, you can not make a reference to a macro.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is not what I said, and is not correct. In a datastep, you must only have data step commands or a macro that resolves to data step commands. Here is a trivial example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro trivial;
%do ii=1 %to 2; y=&amp;amp;ii; output; %end;
%mend

data trivial_data_step;
%trivial
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I thought I could avoid using a DO-loop because the data _null_ step would iterate all records just till the last record.&amp;nbsp; But that's also not the case.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Again, that's not what I said, and not true. data _null_; can indeed iterate through an entire data step. I could have written my macro to use data _null_ to iterate through the entire data set.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Or do I have to use a proc SQL (with a count) to determine the number of rows before the do loop?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PROC SQL works or the %nobs macro works&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 12:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230063#M41702</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-15T12:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230066#M41703</link>
      <description>&lt;P&gt;Thank you very much for correcting me.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 12:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230066#M41703</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2015-10-15T12:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230079#M41706</link>
      <description>&lt;P&gt;Hi, here's one way how to determine how many iterations are needed to append all the data sets in your list ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* make some data sets to use in PROC APPEND;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data class1;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set sashelp.class;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data class2;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set sashelp.class;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* the data set with list of data sets;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data list;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input dset $30.;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;sashelp.class&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;work.class1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;work.class2&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* how many observations in the list of data sets;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data _null_;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;call symputx('ndsets',obs);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;stop;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set list nobs=obs;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* APPEND makes a new data set (specified as the argument) ;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* number of APPEND iterations specified in loop with macro variable NDSETS;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;%macro append(newdataset);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;%do j=1 %to &amp;amp;ndsets;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data _null_;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;rec = &amp;amp;j;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set list point=rec;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;call symputx('name',dset);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;stop;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;proc append base=&amp;amp;newdataset data=&amp;amp;name;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;%end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;%mend;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;%append(class123);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;You could also move the determination of itaerations inside the macr, then specify the data set with the file list as an argument ...&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;%macro append(filelist,newdataset);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;STRONG&gt;data _null_;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;call symputx('ndsets',obs);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;stop;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set &amp;amp;filelist nobs=obs;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;%do j=1 %to &amp;amp;ndsets;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data _null_;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;rec = &amp;amp;j;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set &amp;amp;filelist point=rec;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;call symputx('name',dset);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;stop;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;proc append base=&amp;amp;newdataset data=&amp;amp;name;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;%end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;%mend;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&lt;STRONG&gt;&lt;FONT face="Courier New"&gt;%append(list, class123);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 14:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230079#M41706</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-10-15T14:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230162#M41727</link>
      <description>&lt;P&gt;Here's a shorter method, where data _null_ reads all observations in test.tables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro readAllFiles(table_master=);
    data _null_;
        set test.tables end=eof;
        call symputx('name_dataset'||left(_n_),name_dataset);
        if eof then call symputx('nobs',_n_);
    run;
    %do ii=1 %to &amp;amp;nobs;
        %readOneFile(lib=source,table_in=&amp;amp;&amp;amp;name_dataset&amp;amp;ii,table_out=temp_table)
        proc append ...
        run; 
        %delete_table(table=temp_table)
    %end;
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 21:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230162#M41727</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-15T21:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230194#M41731</link>
      <description>&lt;P&gt;Hi ... could you show a complete example of how that works given the following ... want to append SASHELP.CLASS, CLASS1, CLASS2. &amp;nbsp;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* make some data sets to use in PROC APPEND;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data class1;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set sashelp.class;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data class2;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set sashelp.class;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* the data set with list of data sets;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data list;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input dset $30.;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;sashelp.class&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;work.class1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;work.class2&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 22:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230194#M41731</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-10-15T22:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230196#M41732</link>
      <description>&lt;P&gt;You can use CALL EXECUTE to generate code that will sit on a stack and execute AFTER the data step stops.&lt;/P&gt;
&lt;P&gt;So your DATA step should look something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set test.TABLES;  
   call execute(cats('%nrstr(%readOneFile)'
    ,'(lib=source,table_in=',name_dataset
    ,',table_out=temp_table)'
    ));
   call execute('PROC APPEND BASE=&amp;amp;table_master(compress=yes) DATA=temp_table force; RUN;');
run;

%delete_table(table=temp_table);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Oct 2015 23:33:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230196#M41732</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-10-15T23:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230245#M41737</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892" target="_blank"&gt;@PaigeMiller&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Thank you for sharing this shorter version, which worked very well in my program.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks cleaner then your first solution (which also worked very well).&lt;/P&gt;
&lt;P&gt;If you don't mind, I will change the accepted solution to this second shorter version of you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Thank you for this alternative version.&amp;nbsp; It looks very interesting that you can stack some code while in a datastep to run after a datastep completes.&amp;nbsp; I've learned a lot since the beginning of this thread.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 08:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230245#M41737</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2015-10-16T08:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230268#M41744</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28934"&gt;@fre&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Thank you for sharing this shorter version, which worked very well in my program.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks cleaner then your first solution (which also worked very well).&lt;/P&gt;
&lt;P&gt;If you don't mind, I will change the accepted solution to this second shorter version of you.&lt;/P&gt;
&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28934"&gt;@fre&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm glad you liked the 2nd solution I provided. I often hear people say words like "cleaner", and I'm not sure what you mean by that. Anyway, over many years of programming, I have decided that I prefer the first program to the second program, although that is entirely subjective and I'm not even sure I can state why; but as you said, both work as desired and if you like the second solution better, that's great, I'm glad it works for you.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 12:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230268#M41744</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-16T12:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230273#M41745</link>
      <description>&lt;P&gt;Maybe 'cleaner' wasn't the right word to use.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second solution just looks more efficient (but i'm not sure if it actually is) because you only access the dataset "test.tables" 1 time.&amp;nbsp;&amp;nbsp; In the first solution, it looks like the same table is accessed 100 times.&lt;/P&gt;
&lt;P&gt;Most important is that both solutions work, so I'm already a happy man.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 13:12:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230273#M41745</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2015-10-16T13:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230281#M41746</link>
      <description>&lt;P&gt;I really do not like the idea of generating hundreds of macro variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either use CALL EXECUTE to generate the code or you can actually use a data step to write the code to a file. &amp;nbsp;Writing the code to a file is even easier to debug since you can examine the file and submit pieces of it to make sure your code generation logic is correct.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 13:41:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230281#M41746</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-10-16T13:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230282#M41747</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I really do not like the idea of generating hundreds of macro variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, now that you mention it, I think this is the reason I began using the first code rather than the second code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Either use CALL EXECUTE to generate the code or you can actually use a data step to write the code to a file. &amp;nbsp;Writing the code to a file is even easier to debug since you can examine the file and submit pieces of it to make sure your code generation logic is correct.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This certainly is good advice — however I feel that for me personally, I have reached the point where I can write working macro code without the need for a file of code to help me see if I have gotten it right. So its faster for me to not write the code to a file.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 14:01:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230282#M41747</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-16T14:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: call symput within data _null_: multiple iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230342#M41757</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a pity only one answer can be marked as "the solution".&lt;/P&gt;
&lt;P&gt;Just did some research on 'call execute', and indeed, very powerful too to handle my original question.&lt;/P&gt;
&lt;P&gt;So dear reader, this thread contains at least 3 solutions so far.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 18:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-within-data-null-multiple-iterations/m-p/230342#M41757</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2015-10-16T18:57:02Z</dc:date>
    </item>
  </channel>
</rss>

