<?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 change structure of table from long to wide with one row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646231#M193274</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with 3 rows and 11 columns( one column is char and 10 columns are numeric).&lt;/P&gt;
&lt;P&gt;I want to change the structure of table into one row table with following columns:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;x_a&amp;nbsp; x_b&amp;nbsp; x_all&amp;nbsp;&lt;/P&gt;
&lt;P&gt;y_a y_b y_all&lt;/P&gt;
&lt;P&gt;z_a z_b z_all&lt;/P&gt;
&lt;P&gt;xx_a xx_b xx_all&lt;/P&gt;
&lt;P&gt;yy_a yy_b yy_all&lt;/P&gt;
&lt;P&gt;zz_a zz_b zz_all&lt;/P&gt;
&lt;P&gt;w_a w_b w_all&lt;/P&gt;
&lt;P&gt;.....and so on.&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl1;
input group $ x y z xx yy zz w t q r;
cards;
a 1 2 3 4 5 6 7 8 9 10
b 11 12 13 14 15 16 17 18 19 20
all  3 5 7 9 11 13 17 21 30 40
;
run;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 May 2020 14:57:01 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2020-05-08T14:57:01Z</dc:date>
    <item>
      <title>change structure of table from long to wide with one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646231#M193274</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with 3 rows and 11 columns( one column is char and 10 columns are numeric).&lt;/P&gt;
&lt;P&gt;I want to change the structure of table into one row table with following columns:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;x_a&amp;nbsp; x_b&amp;nbsp; x_all&amp;nbsp;&lt;/P&gt;
&lt;P&gt;y_a y_b y_all&lt;/P&gt;
&lt;P&gt;z_a z_b z_all&lt;/P&gt;
&lt;P&gt;xx_a xx_b xx_all&lt;/P&gt;
&lt;P&gt;yy_a yy_b yy_all&lt;/P&gt;
&lt;P&gt;zz_a zz_b zz_all&lt;/P&gt;
&lt;P&gt;w_a w_b w_all&lt;/P&gt;
&lt;P&gt;.....and so on.&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl1;
input group $ x y z xx yy zz w t q r;
cards;
a 1 2 3 4 5 6 7 8 9 10
b 11 12 13 14 15 16 17 18 19 20
all  3 5 7 9 11 13 17 21 30 40
;
run;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 14:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646231#M193274</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-05-08T14:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: change structure of table from long to wide with one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646239#M193278</link>
      <description>&lt;P&gt;This will create the structure:&lt;/P&gt;
&lt;PRE&gt;proc transpose data=tbl1 out=trans1;
   by notsorted group;

run;

proc transpose data=trans1 out=trans2;
   id _name_ group;
   var col1;
run;&lt;/PRE&gt;
&lt;P&gt;Getting an automatic underscore character isn't going to happen here though. If you read your initial data so the variables x y are x_ y_ (or rename them prior to the Transpose steps) OR have group values of _a _b _all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: if you attempt to extend this you will have problems if you have multiple records with the same group value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 15:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646239#M193278</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-08T15:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: change structure of table from long to wide with one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646244#M193280</link>
      <description>&lt;P&gt;Thanks and perfect!&lt;/P&gt;
&lt;P&gt;What about control the order of colmns same as it was and also by group order&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 15:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646244#M193280</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-05-08T15:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: change structure of table from long to wide with one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646247#M193281</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am thinking about something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=tbl1 out=tbl1_group (drop=_:) prefix=group;
	var group;
run;

data tbl2;

	set tbl1 (drop=group);
	set tbl1_group;
	
	if _N_=1 then do row=1 to 3;
		
		array _group(*) group:;
		array _temp (*) x y z xx yy zz w t q r;
			do col=1 to 10;
				_value=_temp(col);
				_name=catx("_",_group(row), vname(_temp(col)));
				output;
			end;
		end;
	keep _value _name;
run;

proc transpose data=tbl2 out=want (drop=_:);
	var _value;
	id _name;
run;

proc print;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 15:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646247#M193281</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-08T15:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: change structure of table from long to wide with one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646255#M193284</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks and perfect!&lt;/P&gt;
&lt;P&gt;What about control the order of colmns same as it was and also by group order&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What specific purpose is this data set for that the order is critical.?&lt;/P&gt;
&lt;P&gt;I don't normally spend any time with such as when things get to be read by people, where order typically is needed, I do that within a report procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might be able to get what you want/ need with sorting the first output transposed data set. But suspecting that your example x, y, z variables are not the actual names I won't guarantee that will work for any given input.&lt;/P&gt;
&lt;P&gt;You may need to add some variables to deal with the order.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 16:00:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646255#M193284</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-08T16:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: change structure of table from long to wide with one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646256#M193285</link>
      <description>&lt;P&gt;You can definitely tell PROC TRANSPOSE what delimiter to use when constructing names from the id variable values.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.google.com/search?q=%40sas.com+proc+transpose+delim+option" target="_blank" rel="noopener"&gt;https://www.google.com/search?q=%40sas.com+proc+transpose+delim+option&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Added in SAS version 9.2&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/kb/43/589.html" target="_blank" rel="noopener"&gt;https://support.sas.com/kb/43/589.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 16:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-structure-of-table-from-long-to-wide-with-one-row/m-p/646256#M193285</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-08T16:13:22Z</dc:date>
    </item>
  </channel>
</rss>

