<?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: Need help on TRANSPOSE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502380#M134109</link>
    <description>&lt;P&gt;I shameless take sas dataset from&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A id="link_13" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_self"&gt;KurtBremser&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wide; 
input
  ID
  (lt_datetime lp_datetime sp_datetime st_datetime) (:datetime19.)
  lt_mva lt_mwa lp_mva lp_mwa st_mva st_mwa sp_mva sp_mwa
;
format lt_datetime lp_datetime sp_datetime st_datetime datetime19.;
cards; 
1  21JAN2018:00:00:00 17FEB2018:12:30:00 20MAR2018:06:00:00 04MAR2018:04:30:00 11 12 13 14 15 16 17 18 
2  21JAN2017:10:00:00 17FEB2017:03:30:00 20MAR2017:06:30:00 07MAR2017:02:30:00 11 12 13 14 15 16 17 18 
3  21JAN2016:07:00:00 17FEB2016:07:30:00 20MAR2016:08:00:00 09MAR2016:08:00:00 11 12 13 14 15 16 17 18 
; 
run;
proc transpose data=wide out=temp;
by id;
var lt_datetime lp_datetime sp_datetime st_datetime
  lt_mva lt_mwa lp_mva lp_mwa st_mva st_mwa sp_mva sp_mwa;
run;
data temp;
 set temp;
 id1=scan(_name_,1,'_');
 vname=scan(_name_,-1,'_');
run;
proc sort data=temp;
by id id1;
run;
proc transpose data=temp out=temp1;
by id id1;
id vname;
var col1;
run;
data want;
 set temp1;
 drop _name_;
 format datetime datetime19.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 08 Oct 2018 13:00:21 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-10-08T13:00:21Z</dc:date>
    <item>
      <title>Need help on TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502341#M134089</link>
      <description>&lt;P&gt;I am trying to transpose a wide data into a long data. I've tried various settings for TRANSPOSE but it seems like my fundamental for TRANSPOSE is rather weak.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my data:&lt;/P&gt;&lt;PRE&gt;data wide; 
  input ID lt_datetime lp_datetime sp_datetime st_datetime lt_mva lt_mwa lp_mva lp_mwa st_mva st_mwa sp_mva sp_mwa; 
cards; 
1  21JAN2018:00:00:00 17FEB2018:12:30:00 20MAR2018:06:00:00 04MAR2018:04:30:00 11 12 13 14 15 16 17 18 
2  21JAN2017:10:00:00 17FEB2017:03:30:00 20MAR2017:06:30:00 07MAR2017:02:30:00 11 12 13 14 15 16 17 18 
3  21JAN2016:07:00:00 17FEB2016:07:30:00 20MAR2016:08:00:00 09MAR2016:08:00:00 11 12 13 14 15 16 17 18 
; 
run ; 

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want it to look like this:&lt;/P&gt;&lt;PRE&gt;ID  profile datetime             mva   mwa
1   lt      21JAN2018:00:00:00   11    15
1   lp      17FEB2018:12:30:00   12    16
1   st      20MAR2018:06:00:00   13    17
1   sp      04MAR2018:04:30:00   14    18
2   lt      21JAN2017:10:00:00   11    15
2   lp      17FEB2017:03:30:00   12    16
2   st      20MAR2017:06:30:00   13    17
2   sp      07MAR2017:02:30:00   14    18
3   lt      21JAN2016:07:00:00   11    15
3   lp      17FEB2016:07:30:00   12    16
3   st      20MAR2016:08:00:00   13    17
3   sp      09MAR2016:08:00:00   14    18&lt;/PRE&gt;&lt;P&gt;However, i cannot think of the proper logic for it. I had this code that only gives me the result transposed for datetime but not for other mva mwa:&lt;/P&gt;&lt;PRE&gt;proc transpose data =assettnbtjoined out=transposeddt;
var lt_datetime lp_datetime st_datetime sp_datetime;
by newID;
run;&lt;/PRE&gt;&lt;P&gt;Result of the code:&lt;/P&gt;&lt;PRE&gt;newID	_NAME_	_LABEL_	COL1
1	lt_datetime	Local Trough Date and Time	15SEP18:08:00:00
1	lp_datetime	Local Peak Date and Time	28SEP18:12:30:00
1	st_datetime	System Trough Date and Time	09SEP18:08:00:00
1	sp_datetime	System Peak Date and Time	25SEP18:14:30:00
2	lt_datetime	Local Trough Date and Time	15SEP18:08:00:00
2	lp_datetime	Local Peak Date and Time	28SEP18:12:30:00
2	st_datetime	System Trough Date and Time	09SEP18:08:00:00
2	sp_datetime	System Peak Date and Time	25SEP18:14:30:00&lt;/PRE&gt;&lt;P&gt;How do i tweak my code into the result that i want?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 10:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502341#M134089</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-10-08T10:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502348#M134094</link>
      <description>&lt;P&gt;Try this in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wide; 
input
  ID
  (lt_datetime lp_datetime sp_datetime st_datetime) (:datetime19.)
  lt_mva lt_mwa lp_mva lp_mwa st_mva st_mwa sp_mva sp_mwa
;
cards; 
1  21JAN2018:00:00:00 17FEB2018:12:30:00 20MAR2018:06:00:00 04MAR2018:04:30:00 11 12 13 14 15 16 17 18 
2  21JAN2017:10:00:00 17FEB2017:03:30:00 20MAR2017:06:30:00 07MAR2017:02:30:00 11 12 13 14 15 16 17 18 
3  21JAN2016:07:00:00 17FEB2016:07:30:00 20MAR2016:08:00:00 09MAR2016:08:00:00 11 12 13 14 15 16 17 18 
; 
run;

data want (
  keep=id profile datetime mva mwa
);
set wide;
array dt{4} lt_datetime lp_datetime sp_datetime st_datetime;
array mv{4} lt_mva lp_mva st_mva sp_mva;
array mw{4} lt_mwa lp_mwa st_mwa sp_mwa;
array prof{4} $ _temporary_ ('lt','lp','sp','st');
do i = 1 to 4;
  profile = prof{i};
  datetime = dt{i};
  mva = mv{i};
  mwa = mw{i};
  output;
end;
format datetime datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I corrected your example data step (informat for datetime values).&lt;/P&gt;
&lt;P&gt;Note that the order of values in your example data does not match with your expected output.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 11:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502348#M134094</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-08T11:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502380#M134109</link>
      <description>&lt;P&gt;I shameless take sas dataset from&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A id="link_13" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_self"&gt;KurtBremser&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wide; 
input
  ID
  (lt_datetime lp_datetime sp_datetime st_datetime) (:datetime19.)
  lt_mva lt_mwa lp_mva lp_mwa st_mva st_mwa sp_mva sp_mwa
;
format lt_datetime lp_datetime sp_datetime st_datetime datetime19.;
cards; 
1  21JAN2018:00:00:00 17FEB2018:12:30:00 20MAR2018:06:00:00 04MAR2018:04:30:00 11 12 13 14 15 16 17 18 
2  21JAN2017:10:00:00 17FEB2017:03:30:00 20MAR2017:06:30:00 07MAR2017:02:30:00 11 12 13 14 15 16 17 18 
3  21JAN2016:07:00:00 17FEB2016:07:30:00 20MAR2016:08:00:00 09MAR2016:08:00:00 11 12 13 14 15 16 17 18 
; 
run;
proc transpose data=wide out=temp;
by id;
var lt_datetime lp_datetime sp_datetime st_datetime
  lt_mva lt_mwa lp_mva lp_mwa st_mva st_mwa sp_mva sp_mwa;
run;
data temp;
 set temp;
 id1=scan(_name_,1,'_');
 vname=scan(_name_,-1,'_');
run;
proc sort data=temp;
by id id1;
run;
proc transpose data=temp out=temp1;
by id id1;
id vname;
var col1;
run;
data want;
 set temp1;
 drop _name_;
 format datetime datetime19.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Oct 2018 13:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502380#M134109</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-08T13:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502383#M134111</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wide; 
   input ID (lt_datetime lp_datetime sp_datetime st_datetime) (:datetime.) lt_mva lt_mwa lp_mva lp_mwa st_mva st_mwa sp_mva sp_mwa; 
   format lt_datetime lp_datetime sp_datetime st_datetime datetime.;
   cards; 
1  21JAN2018:00:00:00 17FEB2018:12:30:00 20MAR2018:06:00:00 04MAR2018:04:30:00 11 12 13 14 15 16 17 18 
2  21JAN2017:10:00:00 17FEB2017:03:30:00 20MAR2017:06:30:00 07MAR2017:02:30:00 11 12 13 14 15 16 17 18 
3  21JAN2016:07:00:00 17FEB2016:07:30:00 20MAR2016:08:00:00 09MAR2016:08:00:00 11 12 13 14 15 16 17 18 
;;;; 
   run;
proc print;
   run; 
proc transpose data=wide out=tall;
   by id;
   run;
data tall(index=(indx1=(id profile)));
   set tall;
   length profile $2;
   profile = scan(_name_,1,'_');
   _name_ = scan(_name_,-1,'_');
   run;
proc transpose data=tall out=want(drop=_name_);
   by id profile;
   var col1;
   format datetime: datetime.;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 321px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23853iADFADBA4FB83DEA2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 13:02:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502383#M134111</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-10-08T13:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502427#M134117</link>
      <description>&lt;P&gt;THANKS Everyone. You guys helped me so much! I really appreciate it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added a copy statement for my own R&amp;amp;D. I cannot think of the logic to populate the first substation_name_psi to the remaining of the blank within the same newID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyone that can provide me a logic statement in a datastep without a dataline?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas populate issue.PNG" style="width: 464px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23856i8FDABE8AF0491B2C/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas populate issue.PNG" alt="sas populate issue.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 15:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502427#M134117</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-10-08T15:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502430#M134119</link>
      <description>Add to BY statement.</description>
      <pubDate>Mon, 08 Oct 2018 15:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502430#M134119</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-10-08T15:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502614#M134195</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&lt;/P&gt;&lt;P&gt;Thanks everyone for the big help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I now want to transpose data from long to wide. I've followed some guides online. However, after one round of transpose, most of my columns wont be in the transposed table. I want all my other columns that are not transposed to be remained the in "Transposed" table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table below is pending to be transposed.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="before transpose scada.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23888iFFC60E54D1CE75B8/image-size/large?v=v2&amp;amp;px=999" role="button" title="before transpose scada.PNG" alt="before transpose scada.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then use my code below:&lt;/P&gt;&lt;PRE&gt;proc sort data=scadajoinedtable;
by newID voltagetype;
run;

proc transpose data=scadajoinedtable out=finalscadajoinedtranstable;
by newID voltagetype;
id _NAME_ ;
var COL1;
run;&lt;/PRE&gt;&lt;P&gt;And this is what i get:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="after transpose scada.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23889i276138325743AFDF/image-size/large?v=v2&amp;amp;px=999" role="button" title="after transpose scada.PNG" alt="after transpose scada.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;So What i wanted more(columns) are(without transposing these):&lt;/P&gt;&lt;P&gt;substation_psi&lt;/P&gt;&lt;P&gt;power&lt;/P&gt;&lt;P&gt;voltagecalc&lt;/P&gt;&lt;P&gt;current&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way for me to achieve so by tweaking proc transpose or have another round of transpose/data step/merge?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 08:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-TRANSPOSE/m-p/502614#M134195</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-10-09T08:14:16Z</dc:date>
    </item>
  </channel>
</rss>

