<?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: create a list of SAS tables with the same prefix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816545#M322331</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413930"&gt;@afsand&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a list of SAS tables with the same prefix. I am not sure how to do it or if it is possible, but I need to do it with a data step.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why restrict solutions to just one method? PROC SQL works as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set sashelp.vtable(where=(memname=:'RESULT' and libname='WORK'));
    keep memname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as select&amp;nbsp;memname&amp;nbsp;from sashelp.vtable 
    where memname eqt 'RESULT' and libname='WORK';
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 05 Jun 2022 16:04:01 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-06-05T16:04:01Z</dc:date>
    <item>
      <title>create a list of SAS tables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816544#M322330</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a list of SAS tables with the same prefix. I am not sure how to do it or if it is possible, but I need to do it with a data step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The table names will look like this:&amp;nbsp;results_group1, results_group2,.....results_group50.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jun 2022 15:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816544#M322330</guid>
      <dc:creator>afsand</dc:creator>
      <dc:date>2022-06-05T15:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: create a list of SAS tables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816545#M322331</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413930"&gt;@afsand&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a list of SAS tables with the same prefix. I am not sure how to do it or if it is possible, but I need to do it with a data step.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why restrict solutions to just one method? PROC SQL works as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set sashelp.vtable(where=(memname=:'RESULT' and libname='WORK'));
    keep memname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as select&amp;nbsp;memname&amp;nbsp;from sashelp.vtable 
    where memname eqt 'RESULT' and libname='WORK';
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jun 2022 16:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816545#M322331</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-05T16:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: create a list of SAS tables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816547#M322332</link>
      <description>Actually I want to create a list of tables not variables. I need to use only the data step, but I read information from a data step and do some calculations and want to save the results in a series of tables by groupe.&lt;BR /&gt;&lt;BR /&gt;like this:&lt;BR /&gt;&lt;BR /&gt;data results_group1-results_group50;&lt;BR /&gt;set adherants ;&lt;BR /&gt;&lt;BR /&gt;some calculations in between ;&lt;BR /&gt;save results in the group tables;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Sun, 05 Jun 2022 16:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816547#M322332</guid>
      <dc:creator>afsand</dc:creator>
      <dc:date>2022-06-05T16:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: create a list of SAS tables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816548#M322333</link>
      <description>&lt;P&gt;Keep everything in one table, create a group variable, and use BY group processing in whatever you do next.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jun 2022 16:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816548#M322333</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-05T16:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: create a list of SAS tables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816550#M322334</link>
      <description>Hi Kurt,&lt;BR /&gt;&lt;BR /&gt;The group by statement will create a table by group? or it will just group the table?&lt;BR /&gt;I need to have a table for each group.</description>
      <pubDate>Sun, 05 Jun 2022 18:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816550#M322334</guid>
      <dc:creator>afsand</dc:creator>
      <dc:date>2022-06-05T18:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: create a list of SAS tables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816556#M322335</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413930"&gt;@afsand&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Actually I want to create a list of tables not variables.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The code I gave creates a list of tables, not variables. Exactly what you asked for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data results_group1-results_group50;
set adherants ;

some calculations in between ;
save results in the group tables;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As stated by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; , this is not a good idea, keep everything in one data set, and use an indicator or group variable to determine which group it belongs to. Don't try to split the data. Use it as one big data set, you can pull out selected parts as you need them, by using a WHERE statement, or use BY processing to handle all groups.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jun 2022 19:48:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816556#M322335</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-05T19:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: create a list of SAS tables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816559#M322336</link>
      <description>&lt;P&gt;Please explain WHY you want to create multiple datasets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To generate code like that you need to use code generation.&amp;nbsp; Either via the SAS Macro Language or by just writing the code to a text file using a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example if you wanted to generate a data statement that names 50 output datasets you could use code like this to write that to a file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code lrecl=70 ;
  put 'data ' @ ;
  do group=1 to 50;
     put 'results_group' group @;
  end;
  put ';' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now that you have that statement in a file you could include into your program using a %INCLUDE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include code / source2; 
  set adherants ;
/*
some calculations in between ;
save results in the group tables;
*/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that to actually save the results to multiple dataset will also probably involve some type of code generation.&amp;nbsp; Unless you want the same thing written to all 50 datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;5    data class0-class1 ;
                -
                22
                200
ERROR 22-322: Syntax error, expecting one of the following: a name,
              a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

6      set sashelp.class;
7      select (sex='M');
8        when (0) output class0;
9        when (1) output class1;
10     end;
11   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.CLASS0 may be incomplete.  When this step was
         stopped there were 0 observations and 5 variables.
WARNING: The data set WORK.CLASS1 may be incomplete.  When this step was
         stopped there were 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds


12   data class0 class1 ;
13     set sashelp.class;
14     select (sex='M');
15       when (0) output class0;
16       when (1) output class1;
17     end;
18   run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS0 has 9 observations and 5 variables.
NOTE: The data set WORK.CLASS1 has 10 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Jun 2022 20:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816559#M322336</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-05T20:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: create a list of SAS tables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816575#M322337</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413930"&gt;@afsand&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I need to have a table for each group.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's normally sub-optimal design done by SAS users who haven't fully understood yet the power of by-group processing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please tell us WHY you need separate tables and why you can't just have a single table with a variable that stores the group.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jun 2022 23:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816575#M322337</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-06-05T23:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: create a list of SAS tables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816591#M322346</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413930"&gt;@afsand&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;I need to have a table for each group.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No you don't. At least in 99% of cases which we see here. Explain&amp;nbsp;&lt;STRONG&gt;WHY&lt;/STRONG&gt; you&amp;nbsp;&lt;EM&gt;think&lt;/EM&gt; you need separate datasets. Tell us about the further processing you intend to do.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 06:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-list-of-SAS-tables-with-the-same-prefix/m-p/816591#M322346</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-06T06:14:47Z</dc:date>
    </item>
  </channel>
</rss>

