<?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 Tranposing a Table! in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1562#M490</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I am trying to tranpose a table (from Table 1 to Table 2) with ID from column to row, however keeping other data in column as illustrated below. Can any one pl. suggest how it can be done in SAS (using query or transpose task)? Many Thanks,&lt;BR /&gt;
SAS user&lt;BR /&gt;
&lt;BR /&gt;
Table 1 (from)&lt;BR /&gt;
&lt;BR /&gt;
ID	Date	     Time	kWh&lt;BR /&gt;
1	1-Jan-06	9	2&lt;BR /&gt;
1	2-Jan-06	10	3&lt;BR /&gt;
1	3-Jan-06	11	4&lt;BR /&gt;
2	1-Jan-06	9	5&lt;BR /&gt;
2	2-Jan-06	10	6&lt;BR /&gt;
2	3-Jan-06	11	7&lt;BR /&gt;
3	1-Jan-06	9	8&lt;BR /&gt;
3	2-Jan-06	10	9&lt;BR /&gt;
3	3-Jan-06	11	10&lt;BR /&gt;
&lt;BR /&gt;
Table 2 (to this table)&lt;BR /&gt;
			ID	&lt;BR /&gt;
Date	      Time	1	2	3&lt;BR /&gt;
1-Jan-06	9	2	5	8&lt;BR /&gt;
2-Jan-06	10	3	6	9&lt;BR /&gt;
3-Jan-06	11	4	7	10</description>
    <pubDate>Tue, 17 Oct 2006 00:21:29 GMT</pubDate>
    <dc:creator>SMR</dc:creator>
    <dc:date>2006-10-17T00:21:29Z</dc:date>
    <item>
      <title>Tranposing a Table!</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1562#M490</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I am trying to tranpose a table (from Table 1 to Table 2) with ID from column to row, however keeping other data in column as illustrated below. Can any one pl. suggest how it can be done in SAS (using query or transpose task)? Many Thanks,&lt;BR /&gt;
SAS user&lt;BR /&gt;
&lt;BR /&gt;
Table 1 (from)&lt;BR /&gt;
&lt;BR /&gt;
ID	Date	     Time	kWh&lt;BR /&gt;
1	1-Jan-06	9	2&lt;BR /&gt;
1	2-Jan-06	10	3&lt;BR /&gt;
1	3-Jan-06	11	4&lt;BR /&gt;
2	1-Jan-06	9	5&lt;BR /&gt;
2	2-Jan-06	10	6&lt;BR /&gt;
2	3-Jan-06	11	7&lt;BR /&gt;
3	1-Jan-06	9	8&lt;BR /&gt;
3	2-Jan-06	10	9&lt;BR /&gt;
3	3-Jan-06	11	10&lt;BR /&gt;
&lt;BR /&gt;
Table 2 (to this table)&lt;BR /&gt;
			ID	&lt;BR /&gt;
Date	      Time	1	2	3&lt;BR /&gt;
1-Jan-06	9	2	5	8&lt;BR /&gt;
2-Jan-06	10	3	6	9&lt;BR /&gt;
3-Jan-06	11	4	7	10</description>
      <pubDate>Tue, 17 Oct 2006 00:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1562#M490</guid>
      <dc:creator>SMR</dc:creator>
      <dc:date>2006-10-17T00:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: Tranposing a Table!</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1563#M491</link>
      <description>I created and transposed your table 1 in Enterprise Guide by selecting Data&amp;gt;Transpose. Under Task roles, I selected the variable kWh for Transposed variables, id for New column names, date and time for Group analysis by. Under Options, I unchecked Use prefix.  My results looked like your Table 2. &lt;BR /&gt;
&lt;BR /&gt;
This is the SAS code  for the transpose procedure that was generated.&lt;BR /&gt;
&lt;BR /&gt;
 PROC TRANSPOSE DATA=WORK.SORTTempTableSorted&lt;BR /&gt;
	OUT=EGTASK.TRNSTransposedDATA(LABEL="Transposed HDSLIB.DATA")&lt;BR /&gt;
	NAME=Source&lt;BR /&gt;
	LABEL=Label&lt;BR /&gt;
;&lt;BR /&gt;
	BY date time;&lt;BR /&gt;
	ID id;&lt;BR /&gt;
	VAR kwh;</description>
      <pubDate>Tue, 17 Oct 2006 01:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1563#M491</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-10-17T01:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Tranposing a Table!</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1564#M492</link>
      <description>Be cautious as the previous solution works only because Enterprise Guide accepts variable names beginning with digits as default. This is because EG includes the following statement in all programs :&lt;BR /&gt;
OPTIONS VALIDVARNAME=ANY ;&lt;BR /&gt;
&lt;BR /&gt;
In SAS, you should never name variables as 1, 2, 3. But instead KWh1, KWh2, KWh3 would be just fine.&lt;BR /&gt;
So prior the TRANSPOSE procedure, consider creating a new dataset with an extra variable, varName for example, with "KWh"!!id as a formula. Then use it as ID in the Transpose task.&lt;BR /&gt;
&lt;BR /&gt;
Then the created dataset can be used anywhere, in any type of task.&lt;BR /&gt;
&lt;BR /&gt;
Olivier</description>
      <pubDate>Tue, 17 Oct 2006 08:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1564#M492</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2006-10-17T08:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: Tranposing a Table!</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1565#M493</link>
      <description>Oliver made a good point.  If you run the code in SAS, not SAS Enterprise Guide the variable names will be _1 _2 and _3     unless you include the option to take any variable name which you would not do.  &lt;BR /&gt;
&lt;BR /&gt;
If you run it in SAS Enterprise Guide, just keep the include prefix checked and put the prefix as kWh  to get kWh1, kWh2, etc. as the variable names.  &lt;BR /&gt;
&lt;BR /&gt;
Also, I noticed that I left off the sort procedure for the generated code and you need to sort on the BY variables or it will not work.  I have included the entire code and included the PREFIX option on the Proc transpose.  &lt;BR /&gt;
&lt;BR /&gt;
Here it is. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data temp; &lt;BR /&gt;
input ID Date date9. Time kWh;&lt;BR /&gt;
format date date9.;&lt;BR /&gt;
datalines; &lt;BR /&gt;
1 1Jan06    9 2&lt;BR /&gt;
1 2Jan06   10 3&lt;BR /&gt;
1 3Jan06   11 4&lt;BR /&gt;
2 1Jan06    9 5&lt;BR /&gt;
2 2Jan06   10 6&lt;BR /&gt;
2 3Jan06   11 7&lt;BR /&gt;
3 1Jan06    9 8&lt;BR /&gt;
3 2Jan06   10 9&lt;BR /&gt;
3 3Jan06   11 10&lt;BR /&gt;
run; &lt;BR /&gt;
PROC SORT&lt;BR /&gt;
	DATA=WORK.TEMP(KEEP=kWh ID Date Time)&lt;BR /&gt;
	OUT=WORK.SORTTempTableSorted&lt;BR /&gt;
	;&lt;BR /&gt;
	BY Date Time;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
PROC TRANSPOSE DATA=WORK.SORTTempTableSorted&lt;BR /&gt;
   OUT=Trans&lt;BR /&gt;
   NAME=Source&lt;BR /&gt;
   LABEL=Label&lt;BR /&gt;
   Prefix=kWh&lt;BR /&gt;
;&lt;BR /&gt;
BY date time;&lt;BR /&gt;
ID id;&lt;BR /&gt;
VAR kwh; &lt;BR /&gt;
run; &lt;BR /&gt;
proc print data=trans;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 17 Oct 2006 20:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1565#M493</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-10-17T20:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Tranposing a Table!</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1566#M494</link>
      <description>Hi, &lt;BR /&gt;
&lt;BR /&gt;
Many thanks Helen and Olivier. I used Helen's instruction for Enterprise Guide, and it did work for that simple table (I use only the guide at this moment and do not understand programming code yet).   &lt;BR /&gt;
&lt;BR /&gt;
I was actually struggling to create a table which is bit more complicated than the table that I provided before.&lt;BR /&gt;
&lt;BR /&gt;
Is there a way to to create two rows of heading in SAS table outputs (as one can create in Excel)? I would like to convert Table 1 below to Table 2, for example. &lt;BR /&gt;
&lt;BR /&gt;
I would like to have two rows of heading in Table 2, for example, one with No.1., No. 2, etc. And another row, under each of these No.1, No.2, with headings of dates (such as 1 Jan, 2Jan, 3Jan, etc). And my data will have columns of US$ for each of days (1Jan, 2Jan..) under No1, No.2, against time period. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Table1 (From this table)				&lt;BR /&gt;
ID	Date	Time(AM)	US$	&lt;BR /&gt;
No. 1	1-Jan-06	9	200	&lt;BR /&gt;
No. 1	1-Jan-06	10	300	&lt;BR /&gt;
No. 1	1-Jan-06	11	450	&lt;BR /&gt;
No. 1	2-Jan-06	9	150	&lt;BR /&gt;
No. 1	2-Jan-06	10	160	&lt;BR /&gt;
No. 1	2-Jan-06	11	200	&lt;BR /&gt;
No. 1	3-Jan-06	9	144	&lt;BR /&gt;
No. 1	3-Jan-06	10	122				&lt;BR /&gt;
No. 1	3-Jan-06	11	500				&lt;BR /&gt;
No. 2	1-Jan-06	9	235				&lt;BR /&gt;
No. 2	1-Jan-06	10	214				&lt;BR /&gt;
No. 2	1-Jan-06	11	145				&lt;BR /&gt;
No. 2	2-Jan-06	9	254				&lt;BR /&gt;
No. 2	2-Jan-06	10	789				&lt;BR /&gt;
No. 2	2-Jan-06	11	100				&lt;BR /&gt;
No. 2	3-Jan-06	9	500				&lt;BR /&gt;
No. 2	3-Jan-06	10	650				&lt;BR /&gt;
No. 2	3-Jan-06	11	450				&lt;BR /&gt;
							&lt;BR /&gt;
							&lt;BR /&gt;
Table 2 (to this table)							&lt;BR /&gt;
							&lt;BR /&gt;
	Time(AM)	No.1	No. 1	No. 1	No. 2	No. 2	No. 2&lt;BR /&gt;
		1-Jan-06	2-Jan-06	3-Jan-06	1-Jan-06	2-Jan-06	3-Jan-06&lt;BR /&gt;
	9	200	150	144	235	254	500&lt;BR /&gt;
	10	300	160	122	214	789	650&lt;BR /&gt;
	11	450	200	500	145	100	450&lt;BR /&gt;
&lt;BR /&gt;
If one could create a unique column headings by picking names from from two columns. For example, to create a variable name 'No.1 1Jan', 'No1 2Jan' by combining No.1 and dates. Does it make sense?&lt;BR /&gt;
&lt;BR /&gt;
Many thanks.</description>
      <pubDate>Tue, 17 Oct 2006 23:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1566#M494</guid>
      <dc:creator>SMR</dc:creator>
      <dc:date>2006-10-17T23:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Tranposing a Table!</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1567#M495</link>
      <description>If I only wanted the results that you are talking about in a printed form, then I would use Proc Tabulate to produce a Summary Table. However, the column headings will look different from your description.&lt;BR /&gt;
To produce a Summary Table in SAS Enterprise Guide, make your data table active by clicking on it. Then from the Menu bar, select Describe &amp;gt; Summary Tables. &lt;BR /&gt;
&lt;BR /&gt;
Under Task roles make ID, Date, and Time the classification variables and US the analysis variable.   &lt;BR /&gt;
&lt;BR /&gt;
At this point, I wish I could just cut and paste what the Summary table layout looks like but I cannot.&lt;BR /&gt;
  &lt;BR /&gt;
So here goes the steps for the desired layout.&lt;BR /&gt;
Select Summary Tables in the selection pane. Now you want to drag the variables under "Available variables" to the Preview area. Drag the variable Time to under the Box area to make it the Row Variable. Drag the variable US to the right of the box area to make it a column variable. Drag Sum (Sum of values) from under "Analysis Variables" to replace the N (the number of values). Because you only have one value for each ID, date, and time, the sum of the value works. Drag Date over the US variable. Drag ID over the Date variable. If you don't get it quit right, don't forget about the undo arrow on the right of the preview area or right click a cell and select "Remove cells".&lt;BR /&gt;
&lt;BR /&gt;
Click run and see if that is what you want.  &lt;BR /&gt;
&lt;BR /&gt;
However, if you want it as a table similar to what you said above, here are the steps.&lt;BR /&gt;
&lt;BR /&gt;
First of all, if you have not already entered the data, I would just enter the ID values as 1, 2, etc. and not as No. 1, No. 2.&lt;BR /&gt;
&lt;BR /&gt;
Make your data table active and select Data&amp;gt;Filter and Query.  Add all the columns to the query under the tab "Select Data". &lt;BR /&gt;
&lt;BR /&gt;
Next you want to add some computed columns. As was pointed out earlier, it is better to have the column names as  regular SAS variable names so they will not have periods or spaces. Therefore, to get what you want, we will create two computed columns, one to use to create the column name and one to create the label for the column name. &lt;BR /&gt;
(You may have to tell SAS Enterprise Guide that you want to use labels as the column names. I cannot remember if that is the default or not. To do that, go to Tools&amp;gt;Options &amp;gt;Data General and check use labels for column names.)  &lt;BR /&gt;
&lt;BR /&gt;
I created two computed columns. These are the names and the formulas used to build the expression.&lt;BR /&gt;
IDdatelabel  cat('No. ',id,' ', put(date,date7.))    &lt;BR /&gt;
IDdate 	   cat('No',id,'_',   put(date, date7.) )&lt;BR /&gt;
&lt;BR /&gt;
The results looks like:&lt;BR /&gt;
ID        Date      IDdatelabel       Time        US        IDdate&lt;BR /&gt;
1	01JAN2006	No. 1 01JAN06	9	200	No1_01JAN06	&lt;BR /&gt;
1	01JAN2006	No. 1 01JAN06	10	300	No1_01JAN06	&lt;BR /&gt;
1	01JAN2006	No. 1 01JAN06	11	450	No1_01JAN06	&lt;BR /&gt;
1	02JAN2006	No. 1 02JAN06	9	150	No1_02JAN06	&lt;BR /&gt;
1	02JAN2006	No. 1 02JAN06	10	160	No1_02JAN06	&lt;BR /&gt;
1	02JAN2006	No. 1 02JAN06	11	200	No1_02JAN06	&lt;BR /&gt;
1	03JAN2006	No. 1 03JAN06	9	144	No1_03JAN06	&lt;BR /&gt;
1	03JAN2006	No. 1 03JAN06	10	122	No1_03JAN06	&lt;BR /&gt;
1	03JAN2006	No. 1 03JAN06	11	500	No1_03JAN06	&lt;BR /&gt;
2	01JAN2006	No. 2 01JAN06	9	235	No2_01JAN06	&lt;BR /&gt;
2	01JAN2006	No. 2 01JAN06	10	214	No2_01JAN06	&lt;BR /&gt;
2	01JAN2006	No. 2 01JAN06	11	145	No2_01JAN06	&lt;BR /&gt;
2	02JAN2006	No. 2 02JAN06	9	254	No2_02JAN06	&lt;BR /&gt;
2	02JAN2006	No. 2 02JAN06	10	789	No2_02JAN06	&lt;BR /&gt;
2	02JAN2006	No. 2 02JAN06	11	100	No2_02JAN06	&lt;BR /&gt;
2	03JAN2006	No. 2 03JAN06	9	500	No2_03JAN06	&lt;BR /&gt;
2	03JAN2006	No. 2 03JAN06	10	650	No2_03JAN06	&lt;BR /&gt;
2	03JAN2006	No. 2 03JAN06	11	450	No2_03JAN06	 &lt;BR /&gt;
&lt;BR /&gt;
Next select Data&amp;gt;Transpose  to transpose the data. &lt;BR /&gt;
Select Task Roles. &lt;BR /&gt;
Move US to Transpose variables.&lt;BR /&gt;
Move IDdate to New column names.&lt;BR /&gt;
Move Time to Group analysis by&lt;BR /&gt;
Move IDdatelabel to New column labels.&lt;BR /&gt;
Chose Options and uncheck Use Prefix. &lt;BR /&gt;
Run the task. &lt;BR /&gt;
&lt;BR /&gt;
Hopefully, I have included all of the steps and words and that this will help you.  It is clear from this long description that often a picture is worth a thousand words.</description>
      <pubDate>Wed, 18 Oct 2006 03:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Tranposing-a-Table/m-p/1567#M495</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-10-18T03:38:47Z</dc:date>
    </item>
  </channel>
</rss>

