<?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 proc transpose in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose/m-p/466613#M119069</link>
    <description>&lt;P&gt;Hi SAS Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to do transpose the below created macro variable's ( SOURCE_FIELDS, TARGET_FIELDS) into columns like below, which i am using to create dynamic table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;expected transpose -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;source_field1&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;source_field2&amp;nbsp;&lt;/P&gt;&lt;P&gt;source_field3&amp;nbsp;&lt;/P&gt;&lt;P&gt;......so on till 500th attribute&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;target_field1&lt;/P&gt;&lt;P&gt;target_field2,&lt;/P&gt;&lt;P&gt;target_field3&lt;/P&gt;&lt;P&gt;... so on 500th attribute&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using in Dynamic table -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table test_table as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; source_field(i) as target_field(i)&lt;/P&gt;&lt;P&gt;from &amp;lt;table_joins&amp;gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there are around 500 attributes with comma separated by comma in source and target fields.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; PROC SQL;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; SELECT SOURCE_FIELDS ,&amp;nbsp; TARGET_FIELDS&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTO :SOURCE_FIELDS&amp;nbsp; , INTO :TARGET_FIELDS SEPARATED BY ','&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM LOOKUP_TABLE&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;QUIT;&lt;/P&gt;</description>
    <pubDate>Thu, 31 May 2018 19:52:10 GMT</pubDate>
    <dc:creator>SASAna</dc:creator>
    <dc:date>2018-05-31T19:52:10Z</dc:date>
    <item>
      <title>proc transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose/m-p/466613#M119069</link>
      <description>&lt;P&gt;Hi SAS Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to do transpose the below created macro variable's ( SOURCE_FIELDS, TARGET_FIELDS) into columns like below, which i am using to create dynamic table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;expected transpose -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;source_field1&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;source_field2&amp;nbsp;&lt;/P&gt;&lt;P&gt;source_field3&amp;nbsp;&lt;/P&gt;&lt;P&gt;......so on till 500th attribute&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;target_field1&lt;/P&gt;&lt;P&gt;target_field2,&lt;/P&gt;&lt;P&gt;target_field3&lt;/P&gt;&lt;P&gt;... so on 500th attribute&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using in Dynamic table -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table test_table as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; source_field(i) as target_field(i)&lt;/P&gt;&lt;P&gt;from &amp;lt;table_joins&amp;gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there are around 500 attributes with comma separated by comma in source and target fields.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; PROC SQL;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; SELECT SOURCE_FIELDS ,&amp;nbsp; TARGET_FIELDS&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTO :SOURCE_FIELDS&amp;nbsp; , INTO :TARGET_FIELDS SEPARATED BY ','&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM LOOKUP_TABLE&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;QUIT;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 19:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose/m-p/466613#M119069</guid>
      <dc:creator>SASAna</dc:creator>
      <dc:date>2018-05-31T19:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose/m-p/466621#M119073</link>
      <description>&lt;P&gt;Did you try using proc transpose? What happened?&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 20:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose/m-p/466621#M119073</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-05-31T20:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose/m-p/466628#M119076</link>
      <description>&lt;P&gt;Not sure what your trying to do. If you want the macro values separated by comma into a table then try something like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let SOURCE_FIELDS=source_field1,source_field2,source_field3;
data want;
do i=1 to 3;
SOURCE_FIELDS=scan("&amp;amp;SOURCE_FIELDS",i,',');
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 20:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose/m-p/466628#M119076</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-05-31T20:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose/m-p/466634#M119082</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86567"&gt;@SASAna&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to do transpose the below created macro variable's ( SOURCE_FIELDS, TARGET_FIELDS) into columns like below, which i am using to create dynamic table.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Transpose really only means much in terms of a data set. A list of macro variables has no position except a relative text position.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you may be looking for something like:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table test_table as
   %do i = 1 to %sysfunc(countw(&amp;amp;source_fields.));
       %if &amp;amp;i= 1 %then %do;
       source_fields(&amp;amp;i) as target_fields(&amp;amp;i)
       %end;
       %else %do;
       , source_fields(&amp;amp;i) as target_fields(&amp;amp;i)
       %end;
   %end; /* i loop*/
   from &amp;lt;table_joins&amp;gt;;
quit;&lt;/PRE&gt;
&lt;P&gt;for your "dynamic table" code. This is just iterating through the macro variable list. I hope your "source_field" values have the correct table references if any of those variable appear in more than one table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the comma in your separated by might not be needed in this case and a space would do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OR build your "as" clause&amp;nbsp;statements properly in the sql:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#339966" size="5"&gt;PROC SQL;
     SELECT catx(' as ',SOURCE_FIELDS ,  TARGET_FIELDS) as term
           INTO :Aslist BY ','
         FROM LOOKUP_TABLE
           ;
QUIT;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;and use a single macro variable in the later select &amp;amp;aslist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There will be some other macro language bits.&lt;/P&gt;
&lt;P&gt;OR and probably a better idea given the number of values would be to use the LOOKUP_table to generate Call execute statements.&lt;/P&gt;
&lt;P&gt;Which might look something like:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set lookup_table end=last;
  if _n_=1 then call execute("proc sql; create table test_table as "||source_fields||" as "|| target_fields);
  else call execute(", "source_fields||" as "|| target_fields);
  if last then call execute("from &amp;lt;table_joins&amp;gt;;quit;");
run;&lt;/PRE&gt;
&lt;P&gt;of course without seeing what you &amp;lt;table_joins&amp;gt; look like can't be any more specific there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 20:55:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose/m-p/466634#M119082</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-31T20:55:15Z</dc:date>
    </item>
  </channel>
</rss>

