<?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 Data step to create tables based on a column value in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-step-to-create-tables-based-on-a-column-value/m-p/532845#M32976</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a table dynamically based on the column available in a different table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;My &lt;STRONG&gt;source_table&lt;/STRONG&gt; would look like&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Field_No | field_Name&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp;A&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; C&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My &lt;STRONG&gt;target_table&lt;/STRONG&gt; should look like&amp;nbsp;&lt;/P&gt;&lt;P&gt;A | B | C&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently my solution is not so efficient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/*Dynamic table creation*/
	%let  s1=;
/*Column lenght should be 30 characters so I am creating a dummy variable*/
	%let Dummy= 'Dummy_Dummy_Dummy_Dummy_Dummy_Dummy_Dummy';

	proc sql;
		create table TEMP as 
			select 'Hi' as Work from Temp_table where 1=2
		;
	quit;

	proc sort data =   Source_table
		by Field_No;
	run;

	proc sql;
		select Dummy||" as "||fld into :s1 seperated by "," from
		(select "&amp;amp;Dummy" as Dummy,Compress(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(Compress(Compress(Compress(substr(strip(upcase(field_name)),1,30)),"("),")"),'*',''),' ',''),'.',''),'-',''),'&amp;gt;',''),,'s') as FLD from Source_table)
		;
	quit;

	proc sql;
		create table target_table  as 
			select "&amp;amp;Dummy." as value_1,&amp;amp;s1 from TEMP where 1=2;
	quit;&lt;/PRE&gt;&lt;P&gt;Appreciate your support.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Feb 2019 05:52:42 GMT</pubDate>
    <dc:creator>Sudhan</dc:creator>
    <dc:date>2019-02-05T05:52:42Z</dc:date>
    <item>
      <title>Data step to create tables based on a column value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-step-to-create-tables-based-on-a-column-value/m-p/532845#M32976</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a table dynamically based on the column available in a different table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;My &lt;STRONG&gt;source_table&lt;/STRONG&gt; would look like&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Field_No | field_Name&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp;A&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; C&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My &lt;STRONG&gt;target_table&lt;/STRONG&gt; should look like&amp;nbsp;&lt;/P&gt;&lt;P&gt;A | B | C&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently my solution is not so efficient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/*Dynamic table creation*/
	%let  s1=;
/*Column lenght should be 30 characters so I am creating a dummy variable*/
	%let Dummy= 'Dummy_Dummy_Dummy_Dummy_Dummy_Dummy_Dummy';

	proc sql;
		create table TEMP as 
			select 'Hi' as Work from Temp_table where 1=2
		;
	quit;

	proc sort data =   Source_table
		by Field_No;
	run;

	proc sql;
		select Dummy||" as "||fld into :s1 seperated by "," from
		(select "&amp;amp;Dummy" as Dummy,Compress(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(Compress(Compress(Compress(substr(strip(upcase(field_name)),1,30)),"("),")"),'*',''),' ',''),'.',''),'-',''),'&amp;gt;',''),,'s') as FLD from Source_table)
		;
	quit;

	proc sql;
		create table target_table  as 
			select "&amp;amp;Dummy." as value_1,&amp;amp;s1 from TEMP where 1=2;
	quit;&lt;/PRE&gt;&lt;P&gt;Appreciate your support.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 05:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-step-to-create-tables-based-on-a-column-value/m-p/532845#M32976</guid>
      <dc:creator>Sudhan</dc:creator>
      <dc:date>2019-02-05T05:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Data step to create tables based on a column value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-step-to-create-tables-based-on-a-column-value/m-p/532916#M32980</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259982"&gt;@Sudhan&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about something along these lines:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data source_table;
input field_no field_name $;
cards;
1 A
3 C
2 B
;

proc sql noprint;
select catt(field_name, ' char(30)') into :fn separated by ', '
from source_table
order by field_no;

create table target_table
(value_1 char(30), &amp;amp;fn);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Feb 2019 13:16:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-step-to-create-tables-based-on-a-column-value/m-p/532916#M32980</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-02-05T13:16:12Z</dc:date>
    </item>
  </channel>
</rss>

