<?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: do loop for datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482189#M124852</link>
    <description>&lt;P&gt;Thanks. My macro that do the manipulation and calculation takes 2 parameters: library and dataset. How do I edit the following code to do so? I tried but does not work&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; _null_&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; my_datasets&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
call &lt;SPAN class="token keyword"&gt;execute&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'%nrstr(%mymac('lib_name,&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;dataset_name&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'))'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 28 Jul 2018 18:58:44 GMT</pubDate>
    <dc:creator>somebody</dc:creator>
    <dc:date>2018-07-28T18:58:44Z</dc:date>
    <item>
      <title>do loop for datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482179#M124847</link>
      <description>&lt;P&gt;I have a number of datasets (400 of them) which I need to perform some manipulation and calculation. I cannot merge them because each dataset is quite big. how can I efficiently loop through these datasets? Is there a way to create a list, or a dataset that contains these datasets and loop through them?&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jul 2018 15:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482179#M124847</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2018-07-28T15:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: do loop for datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482182#M124848</link>
      <description>&lt;P&gt;Wrap your analysis into a macro with the dataset name as parameter, put your dataset names into a control dataset, and use call execute() in a data step you run from the control dataset to call the macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymac(dataset);
/* your analysis code, use &amp;amp;dataset */
%mend;

data _null_;
set my_datasets;
call execute('%nrstr(%mymac(' !! strip(dataset_name) !! '))');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;dataset_name being a variable in my_datasets that contains the dataset names.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jul 2018 15:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482182#M124848</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-28T15:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: do loop for datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482183#M124849</link>
      <description>Hi:&lt;BR /&gt;  I'm sure there have been many previous postings about using DICTIONARY.TABLES and macro processing to generate a list and then cycle through the list to do a PROC PRINT on each table.&lt;BR /&gt;&lt;BR /&gt;cynthia</description>
      <pubDate>Sat, 28 Jul 2018 15:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482183#M124849</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-07-28T15:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: do loop for datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482187#M124850</link>
      <description>&lt;P&gt;Do your&amp;nbsp;datasets:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Share a name structure&amp;nbsp; (like trades_20170115&amp;nbsp;&amp;nbsp; trades_20170116&amp;nbsp; .....,&amp;nbsp;&amp;nbsp; or&amp;nbsp; sales_ibm, sales_msft, sales_apple)?&lt;/LI&gt;
&lt;LI&gt;Have identical variables in them?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, and if you would prefer to process all of the datasets at one time (say you want to do a proc means on all trades by date), you can&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Utiliize a data set view&amp;nbsp;&amp;nbsp; (as opposed to a data set file), in which:
&lt;OL&gt;
&lt;LI&gt;You can conveniently refer to&amp;nbsp;all (or a major subgroup) of&amp;nbsp;the datasets&lt;/LI&gt;
&lt;LI&gt;Avoid the excessive memory demands of reading in dozens or hundreds of datasets&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vneed / view=vneed;
  set mylib.trades_2017:   open=defer;
  trade_value=price*shares;
run;
proc means data=vneed n min max mean nway sum;
  var volume price trade_value;
  class date stock;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data step creates a data set view named VNEED.&amp;nbsp; It's a view, not a file, so it doesn't write data to disk, and it takes only a second to compile.&amp;nbsp; Instead the data step gets activated only when VNEED is referred to later, and then the generated data is streamed directly to the calling procedure in&amp;nbsp;memory, saving disk activity and time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the above is a compact way to get data for each date*stock combination from all the datasets for 2017.&amp;nbsp; Note the trailing colon in ":set mylib.trades_2017:", which means all the datasets whose names start with trades_2017.&amp;nbsp; The "open=defer" option tells SAS to avoid making an input buffer for each of the incoming datasets.&amp;nbsp; Instead SAS will re-use the same buffer for each dataset in sequence, saving memory.&amp;nbsp; The downsides: (1) each of the datasets should have the same variables, and (2) you can't use a BY statement (which would need to look ahead in each dataset, thereby requiring buffers for each).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jul 2018 17:38:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482187#M124850</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-07-28T17:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: do loop for datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482189#M124852</link>
      <description>&lt;P&gt;Thanks. My macro that do the manipulation and calculation takes 2 parameters: library and dataset. How do I edit the following code to do so? I tried but does not work&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; _null_&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; my_datasets&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
call &lt;SPAN class="token keyword"&gt;execute&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'%nrstr(%mymac('lib_name,&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;dataset_name&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'))'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jul 2018 18:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482189#M124852</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2018-07-28T18:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: do loop for datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482194#M124853</link>
      <description>&lt;P&gt;Use the strip function to get rid of unwanted blanks, and the concatenate operator !!:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('%nrstr(%mymac(' !! strip(lib_name) !! ',' !! strip(dataset_name) !! '))');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also build the string for call execute with the cats() function.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jul 2018 19:04:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-for-datasets/m-p/482194#M124853</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-28T19:04:46Z</dc:date>
    </item>
  </channel>
</rss>

