<?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: how to tranpose mutiple colums in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-tranpose-mutiple-colums/m-p/320997#M70790</link>
    <description>&lt;P&gt;You don't need transpose, you can do it by datastep and retain:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;length&amp;nbsp;&lt;SPAN&gt;firstname $20 lastname $20 tel $15 title $5 address $100; &amp;nbsp;/* adapt length as need */&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set test;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;retain firstname lastname tel title address;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if first.id then call missing(&lt;SPAN&gt;firstname, lastname, tel, title, address);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string = lowcase(string);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if type = 'firstname' then&amp;nbsp;firstname = strip(string); else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if type = 'lastname' then&amp;nbsp;lastname = strip(string); else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if type = 'tel' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; then tel = strip(string); &amp;nbsp;else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if type = 'title' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; then title = strip(string); else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if type = 'address' &amp;nbsp;then address = strip(string); else put '&amp;gt;&amp;gt;&amp;gt;ERROR: Unknown ' string=;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if last.id then output;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drop type string;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Dec 2016 19:39:36 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2016-12-23T19:39:36Z</dc:date>
    <item>
      <title>how to tranpose mutiple colums</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-tranpose-mutiple-colums/m-p/320991#M70788</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;Dear sir/madam;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;I have a huge data set and trying to transpose the data and i have setup test dataset &amp;nbsp;and the required out put are below.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; test;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; userid type $ sting $;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;1 firstname John&lt;/P&gt;&lt;P&gt;1 lastname paul&lt;/P&gt;&lt;P&gt;1 tel 2222222222&lt;/P&gt;&lt;P&gt;1 title coor&lt;/P&gt;&lt;P&gt;1 Address 1243 doglas ave&lt;/P&gt;&lt;P&gt;2 firstname BOB&lt;/P&gt;&lt;P&gt;2 lastname JIM&lt;/P&gt;&lt;P&gt;2 tel 2334444444&lt;/P&gt;&lt;P&gt;2 title dr&lt;/P&gt;&lt;P&gt;2 address 4444 reag st.&lt;/P&gt;&lt;P&gt;3 firstname shar&lt;/P&gt;&lt;P&gt;3 lastname costa&lt;/P&gt;&lt;P&gt;3 tel 444444444&lt;/P&gt;&lt;P&gt;3 title RN&lt;/P&gt;&lt;P&gt;3 address 5453 first street&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;required output.&lt;/FONT&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;userid&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;firstname&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;lastname&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;tel&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;title&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Adddress&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;john&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;paul&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2222222222&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Cr.&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1243 douglas ave&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;BOB&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;JIM&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2334444444&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Dr.&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;4444 reag st.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;shar&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;costa&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;444444444&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;RN&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;5453 first street&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 18:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-tranpose-mutiple-colums/m-p/320991#M70788</guid>
      <dc:creator>tekish</dc:creator>
      <dc:date>2016-12-23T18:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to tranpose mutiple colums</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-tranpose-mutiple-colums/m-p/320996#M70789</link>
      <description>&lt;P&gt;Did you try PROC TRANSPOSE? Your data looks like a perfect example for that tool, assuming that your TYPE variable contains values that are valid SAS names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want ;
  by userid;
  id type;
  var string;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Dec 2016 19:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-tranpose-mutiple-colums/m-p/320996#M70789</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-12-23T19:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to tranpose mutiple colums</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-tranpose-mutiple-colums/m-p/320997#M70790</link>
      <description>&lt;P&gt;You don't need transpose, you can do it by datastep and retain:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;length&amp;nbsp;&lt;SPAN&gt;firstname $20 lastname $20 tel $15 title $5 address $100; &amp;nbsp;/* adapt length as need */&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set test;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;retain firstname lastname tel title address;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if first.id then call missing(&lt;SPAN&gt;firstname, lastname, tel, title, address);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string = lowcase(string);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if type = 'firstname' then&amp;nbsp;firstname = strip(string); else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if type = 'lastname' then&amp;nbsp;lastname = strip(string); else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if type = 'tel' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; then tel = strip(string); &amp;nbsp;else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if type = 'title' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; then title = strip(string); else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if type = 'address' &amp;nbsp;then address = strip(string); else put '&amp;gt;&amp;gt;&amp;gt;ERROR: Unknown ' string=;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if last.id then output;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drop type string;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 19:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-tranpose-mutiple-colums/m-p/320997#M70790</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-23T19:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to tranpose mutiple colums</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-tranpose-mutiple-colums/m-p/321002#M70793</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;You don't need transpose, you can do it by datastep and retain:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;but transpose is dynamic, you don't need to know the variable names ahead of time or how many they are. Otherwise, with RETAIN, you're forced to manually code these.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 20:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-tranpose-mutiple-colums/m-p/321002#M70793</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-23T20:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to tranpose mutiple colums</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-tranpose-mutiple-colums/m-p/321007#M70794</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;, you are right but there are some benefits to the datstep:&lt;/P&gt;
&lt;P&gt;- it enables check the IDs (type - in the example) list and catch mistypes or errors&lt;/P&gt;
&lt;P&gt;- it enables to assign different names then those already in the ID (type)&lt;/P&gt;
&lt;P&gt;- it enables conversion, concatenation or spliting variables in some new ones.&lt;/P&gt;
&lt;P&gt;- it enables control on length and addimg labels and formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe, in the that specific case, transpose is enough and gives a shorter code.&lt;/P&gt;
&lt;P&gt;Then treat the datastep, just as one more possibility and be awuare of its benefits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 21:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-tranpose-mutiple-colums/m-p/321007#M70794</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-23T21:27:33Z</dc:date>
    </item>
  </channel>
</rss>

