<?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: Loop through tables to get min and max value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/575615#M162864</link>
    <description>&lt;P&gt;Quick question, what would I have to add to the code to get the table names to appear?&lt;/P&gt;</description>
    <pubDate>Mon, 22 Jul 2019 23:11:30 GMT</pubDate>
    <dc:creator>RALL</dc:creator>
    <dc:date>2019-07-22T23:11:30Z</dc:date>
    <item>
      <title>Loop through tables to get min and max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/574439#M162322</link>
      <description>&lt;P&gt;Hi, I am trying to create a loop that I can use that will get the min and max value from each column in multiple tables.&amp;nbsp; Can this be done?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 04:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/574439#M162322</guid>
      <dc:creator>RALL</dc:creator>
      <dc:date>2019-07-18T04:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through tables to get min and max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/574449#M162328</link>
      <description>&lt;P&gt;Yes. What does your data look like?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 05:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/574449#M162328</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-07-18T05:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through tables to get min and max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/574450#M162329</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* create an example table */
data class;
set sashelp.class;
run;

/* create a control dataset that holds all our datasets to be investigated */
data datasets;
input libname :$8. memname :$32.;
libname = upcase(libname);
memname = upcase(memname);
/* SAS keeps all libnames and memnames in uppercase */
datalines;
work class
;

/* a macro to calculate the min and max for all nuemric variables in a dataset */
%macro get_minmax(libname=,memname=);
data _null_;
set sashelp.vcolumn (
  where=(libname = "&amp;amp;libname." and memname = "&amp;amp;memname." and type = 'num')
) end=eof;
if _n_ = 1
then call execute('
  proc means data=' !! strip(libname) !! '.' !! strip(memname) !! ' min max;
  var
');
call execute(' ' !! strip(name));
if eof
then call execute('
  ;
  run;
');
run;
%mend;

/* a data step that executes the above macro for all datasets in our reference library */
data _null_;
set datasets;
call execute(cats('%nrstr(%get_minmax(libname=',libname,',memname=',memname,'))'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;           Die Prozedur MEANS

Variable         Minimum         Maximum
----------------------------------------
Age           11.0000000      16.0000000
Height        51.3000000      72.0000000
Weight        50.5000000     150.0000000
----------------------------------------
&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Jul 2019 05:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/574450#M162329</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-18T05:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through tables to get min and max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/574543#M162373</link>
      <description>&lt;P&gt;If you have many table and many variables ,you can run the following code several times by setting FIRSTOBS= and OBS= options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
 set sashelp.vcolumn(keep=libname memname name type
 where=(libname='SASHELP' and type='num') obs=100) end=last; /*change sashelp as your library*/
 if _n_=1 then call execute('proc sql; create table final_want as  '); 
 call execute(catt('select "',memname,'" as memname,','"',name,'"  as name,
min(',name,') as min,max(',name,') as max from sashelp.',memname));	/*change sashelp as your library*/
 if not last then call execute('union');
  else call execute(';quit;');
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Jul 2019 13:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/574543#M162373</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-07-18T13:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through tables to get min and max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/574868#M162508</link>
      <description>Thanks for this, it did the trick.</description>
      <pubDate>Fri, 19 Jul 2019 05:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/574868#M162508</guid>
      <dc:creator>RALL</dc:creator>
      <dc:date>2019-07-19T05:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through tables to get min and max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/575615#M162864</link>
      <description>&lt;P&gt;Quick question, what would I have to add to the code to get the table names to appear?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 23:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/575615#M162864</guid>
      <dc:creator>RALL</dc:creator>
      <dc:date>2019-07-22T23:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through tables to get min and max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/575643#M162883</link>
      <description>&lt;P&gt;Maxim 2: Read the Log. Everything that's happened is in there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need it in the output, add a title:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get_minmax(libname=,memname=);
data _null_;
set sashelp.vcolumn (
  where=(libname = "&amp;amp;libname." and memname = "&amp;amp;memname." and type = 'num')
) end=eof;
if _n_ = 1
then call execute('
  title "Means for ' !! strip(libname) !! '.' !! strip(memname) !! '";
  proc means data=' !! strip(libname) !! '.' !! strip(memname) !! ' min max;
  var
');
call execute(' ' !! strip(name));
if eof
then call execute('
  ;
  run;
');
run;
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 05:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-tables-to-get-min-and-max-value/m-p/575643#M162883</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-23T05:29:04Z</dc:date>
    </item>
  </channel>
</rss>

