<?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: Splitting multiple fields from one row into multiple rows in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-multiple-fields-from-one-row-into-multiple-rows/m-p/644432#M30908</link>
    <description>&lt;P&gt;If you need to generalize this beyond 2 records arrays are your best bet, if it's just two&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt;&amp;nbsp;solution is easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array _time(*) ;
array _long(*);
array _lat(*);

do i=1 to dim(_time);
    time = time(i);
    long = long(i);
    lat = lat(i);

output;
end;

keep NO ID Date Time Long Lat;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second link below has descriptions if you need more details. The first link shows how you can use PROC TRANSPOSE to do this, but you'll see quickly it's more work so the array or SET approach is easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Wide to Long:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326441"&gt;@mlegge&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Good day everyone, this is my first post and I'm still fairly new to SAS, so please be gentle &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Initial data:&lt;/P&gt;
&lt;P&gt;NO ID DATE TIME1 LAT1 LONG1 TIME2 LAT2 LONG2&lt;BR /&gt;01 BB 3Mar20 10:05 44.10 -52.01 10:59 44.15 -52.11&lt;BR /&gt;02 CC 3Mar20 11:15 44.20 -52.22 12:08 44.22 -52.32&lt;BR /&gt;03 DD 3Mar20 12:09 45.30 -52.33 13:44 44.33 -52.43&lt;BR /&gt;04 EE 3Mar20 14:22 44.40 -52.44 15:33 44.55 -52.77&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NO ID DATE TIME LAT LONG&lt;BR /&gt;01 BB 3Mar20 10:05 44.10 -52.01&lt;BR /&gt;02 BB 3Mar20 10:59 44.15 -52.11&lt;BR /&gt;03 CC 3Mar20 11:15 44.20 -52.22&lt;BR /&gt;04 CC 3Mar20 12:08 44.22 -52.32&lt;BR /&gt;05 DD 3Mar20 12:09 45.30 -52.33&lt;BR /&gt;06 DD 3Mar20 13:44 44.33 -52.43&lt;BR /&gt;07 EE 3Mar20 14:22 44.40 -52.44&lt;BR /&gt;08 EE 3Mar20 15:33 44.55 -52.77&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So basically I want to keep all 1's (TIME, LAT, &amp;amp; LONG) on the first line and put all 2's on the second line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried playing around with Transpose but to no success!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 01 May 2020 01:58:03 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-05-01T01:58:03Z</dc:date>
    <item>
      <title>Splitting multiple fields from one row into multiple rows</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-multiple-fields-from-one-row-into-multiple-rows/m-p/644423#M30906</link>
      <description>&lt;P&gt;Good day everyone, this is my first post and I'm still fairly new to SAS, so please be gentle &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Initial data:&lt;/P&gt;&lt;P&gt;NO ID DATE TIME1 LAT1 LONG1 TIME2 LAT2 LONG2&lt;BR /&gt;01 BB 3Mar20 10:05 44.10 -52.01 10:59 44.15 -52.11&lt;BR /&gt;02 CC 3Mar20 11:15 44.20 -52.22 12:08 44.22 -52.32&lt;BR /&gt;03 DD 3Mar20 12:09 45.30 -52.33 13:44 44.33 -52.43&lt;BR /&gt;04 EE 3Mar20 14:22 44.40 -52.44 15:33 44.55 -52.77&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NO ID DATE TIME LAT LONG&lt;BR /&gt;01 BB 3Mar20 10:05 44.10 -52.01&lt;BR /&gt;02 BB 3Mar20 10:59 44.15 -52.11&lt;BR /&gt;03 CC 3Mar20 11:15 44.20 -52.22&lt;BR /&gt;04 CC 3Mar20 12:08 44.22 -52.32&lt;BR /&gt;05 DD 3Mar20 12:09 45.30 -52.33&lt;BR /&gt;06 DD 3Mar20 13:44 44.33 -52.43&lt;BR /&gt;07 EE 3Mar20 14:22 44.40 -52.44&lt;BR /&gt;08 EE 3Mar20 15:33 44.55 -52.77&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So basically I want to keep all 1's (TIME, LAT, &amp;amp; LONG) on the first line and put all 2's on the second line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried playing around with Transpose but to no success!&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 01:00:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Splitting-multiple-fields-from-one-row-into-multiple-rows/m-p/644423#M30906</guid>
      <dc:creator>mlegge</dc:creator>
      <dc:date>2020-05-01T01:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting multiple fields from one row into multiple rows</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-multiple-fields-from-one-row-into-multiple-rows/m-p/644430#M30907</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input NO ID $ DATE : date9. TIME1:time5. LAT1 LONG1 TIME2:time5. LAT2 LONG2;
cards4;
01 BB 3Mar20 10:05 44.10 -52.01 10:59 44.15 -52.11
02 CC 3Mar20 11:15 44.20 -52.22 12:08 44.22 -52.32
03 DD 3Mar20 12:09 45.30 -52.33 13:44 44.33 -52.43
04 EE 3Mar20 14:22 44.40 -52.44 15:33 44.55 -52.77
;;;;
run;

Data want;	
	set have(keep=  ID DATE TIME1 LAT1 LONG1 rename=(TIME1=TIME LAT1=LAT LONG1=LONG))
		have(keep=  ID DATE TIME2 LAT2 LONG2 rename=(TIME2=TIME LAT2=LAT LONG2=LONG));
	by  ID DATE;
	format DATE date9.;
	NO= _n_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 May 2020 01:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Splitting-multiple-fields-from-one-row-into-multiple-rows/m-p/644430#M30907</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2020-05-01T01:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting multiple fields from one row into multiple rows</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-multiple-fields-from-one-row-into-multiple-rows/m-p/644432#M30908</link>
      <description>&lt;P&gt;If you need to generalize this beyond 2 records arrays are your best bet, if it's just two&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt;&amp;nbsp;solution is easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array _time(*) ;
array _long(*);
array _lat(*);

do i=1 to dim(_time);
    time = time(i);
    long = long(i);
    lat = lat(i);

output;
end;

keep NO ID Date Time Long Lat;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second link below has descriptions if you need more details. The first link shows how you can use PROC TRANSPOSE to do this, but you'll see quickly it's more work so the array or SET approach is easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Wide to Long:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326441"&gt;@mlegge&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Good day everyone, this is my first post and I'm still fairly new to SAS, so please be gentle &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Initial data:&lt;/P&gt;
&lt;P&gt;NO ID DATE TIME1 LAT1 LONG1 TIME2 LAT2 LONG2&lt;BR /&gt;01 BB 3Mar20 10:05 44.10 -52.01 10:59 44.15 -52.11&lt;BR /&gt;02 CC 3Mar20 11:15 44.20 -52.22 12:08 44.22 -52.32&lt;BR /&gt;03 DD 3Mar20 12:09 45.30 -52.33 13:44 44.33 -52.43&lt;BR /&gt;04 EE 3Mar20 14:22 44.40 -52.44 15:33 44.55 -52.77&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NO ID DATE TIME LAT LONG&lt;BR /&gt;01 BB 3Mar20 10:05 44.10 -52.01&lt;BR /&gt;02 BB 3Mar20 10:59 44.15 -52.11&lt;BR /&gt;03 CC 3Mar20 11:15 44.20 -52.22&lt;BR /&gt;04 CC 3Mar20 12:08 44.22 -52.32&lt;BR /&gt;05 DD 3Mar20 12:09 45.30 -52.33&lt;BR /&gt;06 DD 3Mar20 13:44 44.33 -52.43&lt;BR /&gt;07 EE 3Mar20 14:22 44.40 -52.44&lt;BR /&gt;08 EE 3Mar20 15:33 44.55 -52.77&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So basically I want to keep all 1's (TIME, LAT, &amp;amp; LONG) on the first line and put all 2's on the second line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried playing around with Transpose but to no success!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 01:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Splitting-multiple-fields-from-one-row-into-multiple-rows/m-p/644432#M30908</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-01T01:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting multiple fields from one row into multiple rows</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-multiple-fields-from-one-row-into-multiple-rows/m-p/644442#M30909</link>
      <description>Awesome, works like a charm! Thank you!</description>
      <pubDate>Fri, 01 May 2020 02:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Splitting-multiple-fields-from-one-row-into-multiple-rows/m-p/644442#M30909</guid>
      <dc:creator>mlegge</dc:creator>
      <dc:date>2020-05-01T02:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting multiple fields from one row into multiple rows</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-multiple-fields-from-one-row-into-multiple-rows/m-p/644443#M30910</link>
      <description>Thanks for the quick reply, I'll keep your solution in mind if I need to keep 3 records or more!</description>
      <pubDate>Fri, 01 May 2020 03:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Splitting-multiple-fields-from-one-row-into-multiple-rows/m-p/644443#M30910</guid>
      <dc:creator>mlegge</dc:creator>
      <dc:date>2020-05-01T03:00:02Z</dc:date>
    </item>
  </channel>
</rss>

