<?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 programatically query SAS tables based on a list within a SAS data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580667#M164965</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Example data sets I would like to summarize separately;
data TABLE_201901_V3;
input store product $ units;
datalines;
1 A 10
2 A 20
3 A 20
;

data TABLE_201812_V1;
input store product $ units;
datalines;
1 A 20
2 A 30
3 A 22
;

data TABLE_201811_V2;
input store product $ units;
datalines;
1 A 30
2 A 40
3 A 23
;

data TABLE_201709_V1;
input store product $ units;
datalines;
1 A 40
2 A 50
3 A 25
;

data TABLE_201603_V1;
input store product $ units;
datalines;
1 A 50
2 A 60
3 A 26
;

*List of the above table names;
data sas_table_names;
informat tbl_name $char15.;
format tbl_name $char15.;
input tbl_name $;
datalines;
TABLE_201901_V3
TABLE_201812_V1
TABLE_201811_V2
TABLE_201709_V1
TABLE_201603_V1
;


data _null_;
 set sas_table_names end=z;
 if _n_=1 then call execute('data temp;set ');
 call execute(' '||tbl_name||' ');
 if z then call execute('indsname=name;n=name;run;');
run;

data want;
do _n_=1 by 1 until(last.product);
 set temp;
 by n product notsorted;
 sum=sum(units,sum);
end;
avg=sum/_n_;
drop sum n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 12 Aug 2019 21:18:25 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-08-12T21:18:25Z</dc:date>
    <item>
      <title>How to programatically query SAS tables based on a list within a SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580662#M164962</link>
      <description>&lt;P&gt;I have a list of around 50 SAS table names within a SAS data set that I would like to query and summarize without typing out 50 different "from" or "set" statements. Is there a way to do this programmatically given the example below? The table names do not necessarily follow a consistent pattern unfortunately. I am using SAS EG 7.15.&amp;nbsp;Thank you for any ideas you may have!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Example data sets I would like to summarize separately;
data TABLE_201901_V3;
input store product $ units;
datalines;
1 A 10
2 A 20
3 A 20
;

data TABLE_201812_V1;
input store product $ units;
datalines;
1 A 20
2 A 30
3 A 22
;

data TABLE_201811_V2;
input store product $ units;
datalines;
1 A 30
2 A 40
3 A 23
;

data TABLE_201709_V1;
input store product $ units;
datalines;
1 A 40
2 A 50
3 A 25
;

data TABLE_201603_V1;
input store product $ units;
datalines;
1 A 50
2 A 60
3 A 26
;

*List of the above table names;
data sas_table_names;
informat tbl_name $char15.;
format tbl_name $char15.;
input tbl_name $;
datalines;
TABLE_201901_V3
TABLE_201812_V1
TABLE_201811_V2
TABLE_201709_V1
TABLE_201603_V1
;

*Example of summary information I would like for each table:
	Where i = a value to differentiate five new data sets
		and &amp;amp;table_reference = each of the five datalines input data sets;
proc sql;
create table summary_&amp;amp;i as
select distinct
	product,
	average(units)
from &amp;amp;table_reference
group by product;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Aug 2019 21:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580662#M164962</guid>
      <dc:creator>gtlightfoot</dc:creator>
      <dc:date>2019-08-12T21:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to programatically query SAS tables based on a list within a SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580667#M164965</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Example data sets I would like to summarize separately;
data TABLE_201901_V3;
input store product $ units;
datalines;
1 A 10
2 A 20
3 A 20
;

data TABLE_201812_V1;
input store product $ units;
datalines;
1 A 20
2 A 30
3 A 22
;

data TABLE_201811_V2;
input store product $ units;
datalines;
1 A 30
2 A 40
3 A 23
;

data TABLE_201709_V1;
input store product $ units;
datalines;
1 A 40
2 A 50
3 A 25
;

data TABLE_201603_V1;
input store product $ units;
datalines;
1 A 50
2 A 60
3 A 26
;

*List of the above table names;
data sas_table_names;
informat tbl_name $char15.;
format tbl_name $char15.;
input tbl_name $;
datalines;
TABLE_201901_V3
TABLE_201812_V1
TABLE_201811_V2
TABLE_201709_V1
TABLE_201603_V1
;


data _null_;
 set sas_table_names end=z;
 if _n_=1 then call execute('data temp;set ');
 call execute(' '||tbl_name||' ');
 if z then call execute('indsname=name;n=name;run;');
run;

data want;
do _n_=1 by 1 until(last.product);
 set temp;
 by n product notsorted;
 sum=sum(units,sum);
end;
avg=sum/_n_;
drop sum n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Aug 2019 21:18:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580667#M164965</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-12T21:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to programatically query SAS tables based on a list within a SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580671#M164969</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192808"&gt;@gtlightfoot&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;I see no reason to create 5 different summary tables. Just add table_reference as a group variable to a concatenated data set and run the summary against it. If you then want the summary for a particular input table, just subset the overall summary by table_reference:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;                                                 
  select tbl_name into :dsn separated by " " from sas_table_names ;
quit ;                                                             
                                                                   
data v / view = v ;                                                
  set &amp;amp;dsn indsname = _t ;                                         
  table_reference = _t ;                                           
run ;                                                              
                                                                   
proc sql ;                                                         
  create table summary as                                          
  select table_reference, product, avg (units) as average          
  from   v                                                         
  group  1, 2                                                      
  ;                                                                
quit ;                                                             
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2019 21:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580671#M164969</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-08-12T21:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to programatically query SAS tables based on a list within a SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580672#M164970</link>
      <description>&lt;P&gt;Very nice &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would make the last step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=temp nway;
    class n product;
    var units;
    output out=stats mean=mean_units;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While there really isn't much difference if you only want the means, as soon as you want other statistics (like minimum, maximum, standard deviations or medians or other percentiles — or heaven forbid you want all of those statistics), its less programming in PROC SUMMARY than doing this in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, the data step solution fails to produce the proper answer if there are missing values in variable UNITS. Opposite is true for PROC SUMMARY.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2019 22:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580672#M164970</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-12T22:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to programatically query SAS tables based on a list within a SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580683#M164972</link>
      <description>&lt;P&gt;Also don't see an actual need for creating extra data sets. I might also consider a different reporting approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=work.temp;
   class name product;
   var units;
   table name,
         product,
         units*mean=''
         ;
run;
&lt;/PRE&gt;
&lt;P&gt;Which allows a number of possible changes with the options from Proc tabulate that you can't do in sql, such as multilabel formats for the product class.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2019 23:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580683#M164972</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-12T23:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to programatically query SAS tables based on a list within a SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580857#M165033</link>
      <description>&lt;P&gt;Guru&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp; Dedicating a special piece of my learning to you(from you) and&amp;nbsp; to my late father&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
 set sas_table_names;
 length store 8 product $8 units 8;
   dcl hash H (dataset:tbl_name,ordered: "A",multidata:'y') ;
   h.definekey  ("product") ;
   h.definedata (all:"y") ;
   h.definedone () ;
   dcl hiter hi('h');
 _rc=hi.first();
  do _n_=1 by 1 while(_rc=0);
   _p=lag(product);
   _sum+units;
   if units&amp;gt;. then _n+1;
   avg=_sum/_n;
   if _p ne product and _p&amp;gt;' ' or _n_=h.num_items then do;
   output;
   call missing(of _:);
   end;
  _rc=hi.next();
  end;
 call missing(of _:,store,product,units);
 h.clear();
 drop _: units store;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 15:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580857#M165033</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-13T15:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to programatically query SAS tables based on a list within a SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580871#M165040</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 16:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-programatically-query-SAS-tables-based-on-a-list-within-a/m-p/580871#M165040</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-08-13T16:07:09Z</dc:date>
    </item>
  </channel>
</rss>

