<?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: Data management in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262766#M51361</link>
    <description>&lt;P&gt;Do you want to keep the other 100 columns or are you okay dropping them entirely?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can drop them, look into proc transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;&lt;BR /&gt;by id loc;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc transpose data=have out=want prefix=LOC;
by id;
var LOC;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Apr 2016 02:01:14 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-04-11T02:01:14Z</dc:date>
    <item>
      <title>Change Data Structure - Transpose from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262764#M51359</link>
      <description>&lt;P&gt;Dear SAS users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a large dataset with over 500k rows and over 100 variables (columns). However, I am interested particularlly in two columns called ID (identification) and LOC (location) assigned as values as A, B, or C. The ID column include multiple entries of same ID or sometimes single entry.&lt;/P&gt;
&lt;P&gt;My question is, how I can create three additional columns say LOC1, LOC2, and LOC 3 of data based on oriiginal LOC. For example, say if the first ID 'A1000' has 6 entries (rows) with three rows of A, one of&amp;nbsp; B, and two of C in original LOC, now I want only one row of ID 'A1000' but three additional columns (LOC1, LOC2, LOC3) with a value of 3 in LOC1, with a value of 1 in LOC2, and similarly a value of 2 in LOC3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would appreciate very much for any help.&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 02:02:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262764#M51359</guid>
      <dc:creator>sijansap</dc:creator>
      <dc:date>2016-04-11T02:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: Data management</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262765#M51360</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=sashelp.class noprint;
tables sex*age/out=temp list;
run;
proc transpose data=temp out=want;
by sex;
var count;
id age;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2016 01:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262765#M51360</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-11T01:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Data management</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262766#M51361</link>
      <description>&lt;P&gt;Do you want to keep the other 100 columns or are you okay dropping them entirely?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can drop them, look into proc transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;&lt;BR /&gt;by id loc;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc transpose data=have out=want prefix=LOC;
by id;
var LOC;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2016 02:01:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262766#M51361</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-11T02:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: Data management</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262775#M51365</link>
      <description>&lt;P&gt;Thanks. I will try.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 02:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262775#M51365</guid>
      <dc:creator>sijansap</dc:creator>
      <dc:date>2016-04-11T02:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Data management</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262776#M51366</link>
      <description>Thanks. I will give a try keeping just two columns.</description>
      <pubDate>Mon, 11 Apr 2016 02:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262776#M51366</guid>
      <dc:creator>sijansap</dc:creator>
      <dc:date>2016-04-11T02:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Change Data Structure - Transpose from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262834#M51396</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition to the great answers given, you could also do it in a datastep:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  by id loc;
  array loc_{3} 8;
  retain loc_:;
  if first.loc then call missing(of loc_{*});
  select(loc);
    when("A") loc_{1}=sum(loc_{1},1);
    when("B") loc_{2}=sum(loc_{2},2);
    when("C") loc_{3}=sum(loc_{3},3);
    otherwise;
  end;
  if last.id then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2016 08:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262834#M51396</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-11T08:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Change Data Structure - Transpose from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262893#M51424</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80618"&gt;@sijansap﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's another data step approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.id);
  set have(keep=id loc);
  by id;
  array x loc1-loc3;
  i=whichc(loc, 'A', 'B', 'C');
  if i then x{i}=sum(x{i},1);
end;
drop i loc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 13:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-Data-Structure-Transpose-from-long-to-wide/m-p/262893#M51424</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-11T13:22:28Z</dc:date>
    </item>
  </channel>
</rss>

