<?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: Performing the same analysis on many data tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298468#M62776</link>
    <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understood parts 4 and 5 which are making a macro and indeed it works when I do the data tables one by one like this:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%summarize&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(cities&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%summarize&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(countries&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;/CODE&gt;etc&lt;/PRE&gt;
&lt;P&gt;But is it possible to make a code which will run the same macro but for a list of data tables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 14 Sep 2016 23:57:09 GMT</pubDate>
    <dc:creator>ilikesas</dc:creator>
    <dc:date>2016-09-14T23:57:09Z</dc:date>
    <item>
      <title>Performing the same analysis on many data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298190#M62689</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have many data tables each corresponding to a city (such as new_york, boston etc). In each data table I have data for a person's age. salary and number of childern, and I would to make the following proc means for these variables in the following way:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;means&lt;/STRONG&gt; data=new_york n mean max min range std ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;age salary children;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But instead of doing this manually for each city, is it possible to do this for a list of cities, some sort of "macro for data tables?"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 01:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298190#M62689</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-09-14T01:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Performing the same analysis on many data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298191#M62690</link>
      <description>&lt;P&gt;Why do you have a table for each city? Can you combine them into one? That would be the fastest way.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 02:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298191#M62690</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-14T02:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Performing the same analysis on many data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298195#M62691</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The tables are separate, but is there a way to combine them? (I assume that a new column "city" should be added which wil contain the city's name in it, but I can't figure out how)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 02:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298195#M62691</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-09-14T02:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Performing the same analysis on many data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298202#M62692</link>
      <description>&lt;P&gt;Use indsname= option in the set statement to get the dataset name&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
set NewYork Boston ... indsname=source;
city = source;
run;

proc means data=all ...;
by city;
var ...;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Sep 2016 02:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298202#M62692</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-09-14T02:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Performing the same analysis on many data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298204#M62693</link>
      <description>&lt;PRE&gt;

You can combine these tables together firstly:

data want;
 set NewYork Boston .......   indsname=indsname;
dsn=indsname;
run;

Then run BY statement:

proc means data=want;
by dsn;
.........

&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Sep 2016 03:01:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298204#M62693</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-14T03:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: Performing the same analysis on many data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298205#M62694</link>
      <description>&lt;P&gt;Hi PGStats,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks for the code, it works perfectly!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please give me a general solution for the case where I have many data tables but the variables in each table might be diferent so that I can make a proc means for all of the variables for all the data tables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 03:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298205#M62694</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-09-14T03:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: Performing the same analysis on many data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298206#M62695</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thnka sofr the code, it works greatly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just as I asked PGStats, is it possible to a more general solution for the case where I have many data tables and the variables in each table might be different so that I can do a proc means for all the variables for all the tables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 03:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298206#M62695</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-09-14T03:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Performing the same analysis on many data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298210#M62696</link>
      <description>&lt;P&gt;1. Write the code for base case&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc means data=mydataset n min mean max;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. Determine fields that need to change in each iteration - these will be macro variable parameters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc means data=&lt;U&gt;&lt;STRONG&gt;mydataset&lt;/STRONG&gt;&lt;/U&gt; ... ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dataset variable name will need to change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Convert to macro variable&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsin=mydataset;

Proc means data = &amp;amp;dsin ...
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;4. Wrap in macro code and convert macro variables to parameters.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro summarize(data_in);

Proc means data=&amp;amp;data_in n min mean max;
Run;

%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;5.&lt;/P&gt;
&lt;P&gt;Execute macro for desired dataset&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%summarize(sashelp.class);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Intro to macro language&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="http://www.ats.ucla.edu/stat/sas/seminars/sas_macros_introduction/" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/seminars/sas_macros_introduction/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 04:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298210#M62696</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-14T04:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: Performing the same analysis on many data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298468#M62776</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understood parts 4 and 5 which are making a macro and indeed it works when I do the data tables one by one like this:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%summarize&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(cities&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%summarize&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(countries&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;/CODE&gt;etc&lt;/PRE&gt;
&lt;P&gt;But is it possible to make a code which will run the same macro but for a list of data tables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 23:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298468#M62776</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-09-14T23:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Performing the same analysis on many data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298471#M62777</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12982"&gt;@ilikesas﻿&lt;/a&gt;&amp;nbsp;Yes. Look at CALL EXECUTE. The example in the documentation is very clear.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need further help with it, post what you've tried and highlight what isn't working.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 00:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298471#M62777</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-15T00:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Performing the same analysis on many data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298500#M62786</link>
      <description>&lt;P&gt;Thanks Reeza for the direction, the ucla link does actually have prety much the same thing and I got my wanted result!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But just one thing that I would like to note. Here is my code :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let data_list = boston new_york

%macro means_for_all(all_data);
  %let k=1;
  %let the_data= %scan(&amp;amp;all_data, &amp;amp;k);
  %do %while("&amp;amp;the_data" NE "");
    title "data table is &amp;amp;the_data";
    proc means data=&amp;amp;the_data n min max mean;
      var _all_;
    run;
    %let k = %eval(&amp;amp;k + 1);
    %let the_data = %scan(&amp;amp;all_data, &amp;amp;k);
  %end;
%mend;


%means_for_all(&amp;amp;data_list)
&lt;/PRE&gt;
&lt;P&gt;First I put the names of the tables into a macro variable "&amp;amp;data_list". Then when I run the macro the way above, i.e I put &amp;nbsp;"&amp;amp;data_list" inside the parantheses, I get error messages such as work.data.mean doesn't exist, so for some reason sas treats the proc means options as if they were data names, BUT the result is the same as if when calling the macro I had inputted the variable names one by one, strange...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 04:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Performing-the-same-analysis-on-many-data-tables/m-p/298500#M62786</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-09-15T04:51:34Z</dc:date>
    </item>
  </channel>
</rss>

