<?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: Generate multiple tables with different names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/379039#M91188</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154084"&gt;@capam&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the quick response. I tried your 3rd suggestion and got the following error message. Should there be a format declaration?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 + proc sql;&lt;BR /&gt;2 + %split(3725)&lt;BR /&gt;MLOGIC(SPLIT): Beginning execution.&lt;BR /&gt;MLOGIC(SPLIT): Parameter NUM has value 3725&lt;BR /&gt;MPRINT(SPLIT): create table DWM_3725_Min_list as select t1.* from DWM_Min_list t1 WHERE t1.VEHICLE_NO = 3725 ;&lt;BR /&gt;ERROR: Expression using equals (=) has components that are of different data types.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;You need to start with knowing what code you want to generate before you can really get any code generation project to work.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems clear from that error message that VEHICLE_NO is not a number. It is a string. It might be as simple as changing the where clause to add quotes around the value so that you are generating a string literal instead of numeric literal.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE t1.VEHICLE_NO = "&amp;amp;num"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but you would need to know how the character strings are actually stored to know&amp;nbsp;if that will work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jul 2017 14:44:57 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-07-25T14:44:57Z</dc:date>
    <item>
      <title>Generate multiple tables with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/378991#M91164</link>
      <description>&lt;P&gt;The code below illustrates the concept of creating subtables from a larger tables based on vehicle numbers. I'm not sure of the syntax in 'create table'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro tableLoop;
proc sql;
array VehNo[3] _temporary_ (3725:3727)
do _n_ = 1 to 3;
create table DWM_&amp;amp;VehNo[_n_]_Min_list as
select t1.*
FROM DWM_Min_list t1
WHERE t1.VEHICLE_NO = VehNo[_n_];
end;
/*
array VehNo[60] _temporary_ (3725:3763 6502 6505 6506 6854 6860 
6924 6928 8029 8037 8057 8098 8106 8125 8132 8145) 
*/
quit;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jul 2017 13:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/378991#M91164</guid>
      <dc:creator>capam</dc:creator>
      <dc:date>2017-07-25T13:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Generate multiple tables with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/379013#M91174</link>
      <description>&lt;P&gt;In general it is probably a bad idea to split your nice dataset into lots of little datasets.&lt;/P&gt;
&lt;P&gt;But here are some concepts that might help.&lt;/P&gt;
&lt;P&gt;1) You can generate multiple datasets in one data step. That could save a lot of I/O time since you will only need to read the input dataset once. &amp;nbsp;Something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dwm_6502 dwm_6505 dwm_ 6506;
 set dwm_all ;
 if vehicle_no = 6502 then output dwm_6502;
 else if vehicle_no = 6505 then output dwm_6505;
 else if vehicle_no = 6506 then output dwm_6506;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) If you want to use concepts like ARRAYs and numreic ranges specified by low:high syntax then you will need to use a data step instead of macro code. &amp;nbsp;But for this type of data driven code generation it is easier to use a data step to generate the code than macro code to generate the code anyway. &amp;nbsp;So you might try something like this to write many separate data steps (or create table statements if you prefer).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;file code temp;
data _null_;
  file code;
  array VehNo[200] _temporary_ 
  (3725:3763 6502 6505 6506 6854 6860 6924 6928 8029 8037 8057 8098 8106 8125 8132 8145) 
  ;
  do i=1 to dim(VehNo) while (VehNo(i) ne .) ;
     num=VehNo(i);
     put 
/ 'create table DWM_' num +(-1) '_Min_list as'
/ '  select t1.*'
/ '  from DWM_Min_list t1'
/ '  WHERE t1.VEHICLE_NO = ' num 
/ ';'
    ;
  end;
run;

proc sql;
%include code / source2;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3) Another way is to create a macro to process one Vehicle number. &amp;nbsp;Then use the data step to generate the macro calls.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split(num);
create table DWM_&amp;amp;num._Min_list as
  select t1.*
  from DWM_Min_list t1
  WHERE t1.VEHICLE_NO = &amp;amp;num 
;
%mend split;

data _null_;
  array VehNo[200] _temporary_ 
  (3725:3763 6502 6505 6506 6854 6860 6924 6928 8029 8037 8057 8098 8106 8125 8132 8145) 
  ;
  call execute('proc sql;');
  do i=1 to dim(VehNo) while (VehNo(i) ne .) ;
     call execute(cats('%nrstr(%split)(',VehNo(i),')'));
  end;
  call execute('quit;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 14:10:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/379013#M91174</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-25T14:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: Generate multiple tables with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/379017#M91176</link>
      <description>&lt;P&gt;Neither Array nor DO loop are allowed in Proc SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The create table would not accept a data set type variable in creating the name for the table. A MACRO loop %do would though the structure would have to be somewhat different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are attempting to create a data set for each value of a given variable please describe why. In most cases any processing along those lines works much better with BY group processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before you started to write this macro did you have any working base SAS code? That is generally a requirement before writing a macro to run a loop or parameterized version of code.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 14:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/379017#M91176</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-25T14:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Generate multiple tables with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/379027#M91184</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the quick response. I tried your 3rd suggestion and got the following error message. Should there be a format declaration?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 + proc sql;&lt;BR /&gt;2 + %split(3725)&lt;BR /&gt;MLOGIC(SPLIT): Beginning execution.&lt;BR /&gt;MLOGIC(SPLIT): Parameter NUM has value 3725&lt;BR /&gt;MPRINT(SPLIT): create table DWM_3725_Min_list as select t1.* from DWM_Min_list t1 WHERE t1.VEHICLE_NO = 3725 ;&lt;BR /&gt;ERROR: Expression using equals (=) has components that are of different data types.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 14:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/379027#M91184</guid>
      <dc:creator>capam</dc:creator>
      <dc:date>2017-07-25T14:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Generate multiple tables with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/379039#M91188</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154084"&gt;@capam&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the quick response. I tried your 3rd suggestion and got the following error message. Should there be a format declaration?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 + proc sql;&lt;BR /&gt;2 + %split(3725)&lt;BR /&gt;MLOGIC(SPLIT): Beginning execution.&lt;BR /&gt;MLOGIC(SPLIT): Parameter NUM has value 3725&lt;BR /&gt;MPRINT(SPLIT): create table DWM_3725_Min_list as select t1.* from DWM_Min_list t1 WHERE t1.VEHICLE_NO = 3725 ;&lt;BR /&gt;ERROR: Expression using equals (=) has components that are of different data types.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;You need to start with knowing what code you want to generate before you can really get any code generation project to work.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems clear from that error message that VEHICLE_NO is not a number. It is a string. It might be as simple as changing the where clause to add quotes around the value so that you are generating a string literal instead of numeric literal.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE t1.VEHICLE_NO = "&amp;amp;num"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but you would need to know how the character strings are actually stored to know&amp;nbsp;if that will work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 14:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/379039#M91188</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-25T14:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Generate multiple tables with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/379045#M91191</link>
      <description>Thanks Tom. It was that simple.</description>
      <pubDate>Tue, 25 Jul 2017 14:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-multiple-tables-with-different-names/m-p/379045#M91191</guid>
      <dc:creator>capam</dc:creator>
      <dc:date>2017-07-25T14:51:36Z</dc:date>
    </item>
  </channel>
</rss>

