<?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: SQL Create Table using variable names from SAS Catalog in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573109#M12443</link>
    <description>&lt;P&gt;It does not seem to work.&lt;/P&gt;&lt;P&gt;I changed it to "myname"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data variable_names;
	input var_names $32.;
	datalines;
name
age
sex
height
weight
;
run;

filename myname catalog "work.catalog.mycode1.source";
filename abbrev catalog "work.catalog";

data adfadsf;
	file myname;
	set variable_names end=eof;
	_var_names=cats(',',var_names);

	if _n_ =1 then
		do;
			put "select";
			put var_names;
		end;
	else put _var_names;
run;

proc sql;
	create table t2 as
		%include myname;
	from sashelp.class
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 12 Jul 2019 14:29:43 GMT</pubDate>
    <dc:creator>david27</dc:creator>
    <dc:date>2019-07-12T14:29:43Z</dc:date>
    <item>
      <title>SQL Create Table using variable names from SAS Catalog</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573102#M12439</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this code and &lt;STRONG&gt;&lt;FONT color="#99CC00"&gt;it works fine:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data variable_names;
	input var_names $32.;
	datalines;
name
age
sex
height
weight
;
run;

filename varname catalog "work.catalog.mycode1.source";
filename abbrev catalog "work.catalog";

data adfadsf;
	file varname;
	set variable_names end=eof;
	_var_names=cats(',',var_names);

	if _n_ =1 then
		do;
			put "select";
			put var_names;
		end;
	else put _var_names;
run;

proc sql;
		%include varname;
	from sashelp.class
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please notice ABOVE: I am NOT creating a table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;But if I try to create a Table and the code errors out.&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table t2 as
		%include varname;
	from sashelp.class
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS_ERROR_20190712.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31013i56D0C478EA3897C6/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAS_ERROR_20190712.PNG" alt="SAS_ERROR_20190712.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 14:08:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573102#M12439</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2019-07-12T14:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Create Table using variable names from SAS Catalog</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573103#M12440</link>
      <description>&lt;P&gt;We need to know what is contained in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;work.catalog.mycode1.source&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as clearly, the usage of this code isn't working if you are using SQL to create a table.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 14:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573103#M12440</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-12T14:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Create Table using variable names from SAS Catalog</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573105#M12441</link>
      <description>&lt;P&gt;instead of %include varname, try with var_name, because varname is a keyword in sas&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 14:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573105#M12441</guid>
      <dc:creator>Kayalvizhi</dc:creator>
      <dc:date>2019-07-12T14:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Create Table using variable names from SAS Catalog</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573107#M12442</link>
      <description>&lt;P&gt;and How can I find that?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 14:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573107#M12442</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2019-07-12T14:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Create Table using variable names from SAS Catalog</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573109#M12443</link>
      <description>&lt;P&gt;It does not seem to work.&lt;/P&gt;&lt;P&gt;I changed it to "myname"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data variable_names;
	input var_names $32.;
	datalines;
name
age
sex
height
weight
;
run;

filename myname catalog "work.catalog.mycode1.source";
filename abbrev catalog "work.catalog";

data adfadsf;
	file myname;
	set variable_names end=eof;
	_var_names=cats(',',var_names);

	if _n_ =1 then
		do;
			put "select";
			put var_names;
		end;
	else put _var_names;
run;

proc sql;
	create table t2 as
		%include myname;
	from sashelp.class
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jul 2019 14:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573109#M12443</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2019-07-12T14:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Create Table using variable names from SAS Catalog</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573110#M12444</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215179"&gt;@david27&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;and How can I find that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't you know what is in that catalog entry you call varname? If not, why are you trying to use it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, it appears that %include cannot be used inside the CREATE TABLE clause.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 14:39:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573110#M12444</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-12T14:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Create Table using variable names from SAS Catalog</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573111#M12445</link>
      <description>&lt;P&gt;Sir,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in that catalog entry this is what is supposed to be:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;name&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;,age&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;,sex&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;,height&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;,weight&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Why I say that:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Because the query works when i am not doing a "create table.."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am learning how to use catalog and came across this issue. So reaching out to more knowledgable folks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 14:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573111#M12445</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2019-07-12T14:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Create Table using variable names from SAS Catalog</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573113#M12447</link>
      <description>&lt;P&gt;&lt;SPAN&gt;It appears that %include cannot be used inside the CREATE TABLE clause.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Which brings up the question ... why store part of your code in this catalog entry, and then try to insert it into other code, why not just have it all in one program without the need for a catalog entry?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 14:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573113#M12447</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-12T14:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Create Table using variable names from SAS Catalog</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573118#M12449</link>
      <description>&lt;P&gt;It is really not a good idea to try to use %INCLUDE to include PART of a statement from a text file. (A source catalog is just another way to store a text file)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It can work if you use it to include the BEGINNING of a statement by not including a trailing semi-colon in the text file, but not when you want to stick it into the middle of a statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So either put the beginning of the statement into the code file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or make a new code file and put that into it and use the new file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename create temp;
data _null_;
  file create ;
  if _n_=1 then put 'create table t2 as' ;
  infile varname;
  input ;
  put _infile_;
run;

proc sql;
%include create/source2;
from sashelp.class
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another trick would be a include a reference to a macro variable at the top of your include file.&amp;nbsp; Then change the value of the macro variable.&amp;nbsp; So your include file might look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;headercode.
select 
 name
,age
,sex&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you two programs are then:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
%let headercode=;
%include varnames;
from sashelp.class;

%let headercode=create table t2 as ;
%include varnames;
from sashelp.class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jul 2019 14:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573118#M12449</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-12T14:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Create Table using variable names from SAS Catalog</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573121#M12450</link>
      <description>&lt;P&gt;The variable names are macro driven.&lt;/P&gt;&lt;P&gt;It is possible the variable names will exceed the length of 65K in a very near future for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So instead of doing a select into:..... then creating a macro and doing &amp;amp;variablenames.&lt;/P&gt;&lt;P&gt;I adopted the catalog approach.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 14:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Create-Table-using-variable-names-from-SAS-Catalog/m-p/573121#M12450</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2019-07-12T14:54:00Z</dc:date>
    </item>
  </channel>
</rss>

