<?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 transpose data in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752791#M237162</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I understood the code .&lt;BR /&gt;If we have a number of tests, what can we do.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maxim 14. Use PROC TRANSPOSE or PROC REPORT, and be done with it.&lt;/P&gt;</description>
    <pubDate>Thu, 08 Jul 2021 08:13:49 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-07-08T08:13:49Z</dc:date>
    <item>
      <title>how to transpose data in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752781#M237155</link>
      <description>&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;type&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;score&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; testA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; testB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89&lt;/P&gt;
&lt;P&gt;102&amp;nbsp; &amp;nbsp; &amp;nbsp; testA&amp;nbsp; &amp;nbsp; &amp;nbsp; 89&lt;/P&gt;
&lt;P&gt;102&amp;nbsp; &amp;nbsp; &amp;nbsp; testB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89&lt;/P&gt;
&lt;P&gt;I have one dataset like above how to transpose the data in proc sql ?&lt;/P&gt;
&lt;P&gt;Output should be like see below example:&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; testA&amp;nbsp; &amp;nbsp; testB&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp;89&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 89&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; 89&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We should do in proc sql only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 07:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752781#M237155</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2021-07-08T07:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose data in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752784#M237158</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;. it's possible with the help of case and Join statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql ;
create table want as
select a.id,testA,testB from
(select id, 
case when type eq 'testA' then score end as testA
from have where calculated testA ne .) as a,
(select id, 
case when type eq 'testB' then score end as testB
from have where calculated testb ne .) as b where a.id eq b.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 08:02:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752784#M237158</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2021-07-08T08:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose data in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752786#M237159</link>
      <description>I understood the code .&lt;BR /&gt;If we have a number of tests, what can we do.&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Jul 2021 08:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752786#M237159</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2021-07-08T08:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose data in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752787#M237160</link>
      <description>Better to use PROC TRANSPOSE or ARRAY.</description>
      <pubDate>Thu, 08 Jul 2021 08:04:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752787#M237160</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2021-07-08T08:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose data in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752790#M237161</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ type $ score;
datalines;
101 testA 89
101 testB 90
102 testA 91
102 testB 92
;

proc sql;
create table want as
  select
    id,
    max(case
      when type = "testA"
      then score
      else .
    end) as testA,
    max(case
      when type = "testB"
      then score
      else .
    end) as testB
  from have
  group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But mind that this will be a maintenance nightmare if the contents of variable type change, or need some extra macro coding to make it adaptive.&lt;/P&gt;
&lt;P&gt;That's why there must be a &lt;STRONG&gt;VERY GOOD&lt;/STRONG&gt; reason to not do it with PROC TRANSPOSE, which is much simpler to code and maintains itself:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want (drop=_name_);
by id;
id type;
var score;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also note that wide datasets are always harder to code against, and if this is supposed to create a report, PROC REPORT does this on the fly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=have;
column id score,type;
define id / group;
define score / "" analysis;
define type / "" across;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Jul 2021 08:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752790#M237161</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-08T08:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose data in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752791#M237162</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I understood the code .&lt;BR /&gt;If we have a number of tests, what can we do.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maxim 14. Use PROC TRANSPOSE or PROC REPORT, and be done with it.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 08:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752791#M237162</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-08T08:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose data in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752827#M237173</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; says:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;But mind that this will be a maintenance nightmare if the contents of variable type change, or need some extra macro coding to make it adaptive.&lt;/P&gt;
&lt;P&gt;That's why there must be a &lt;STRONG&gt;VERY GOOD&lt;/STRONG&gt; reason to not do it with PROC TRANSPOSE, which is much simpler to code and maintains itself:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Also note that wide datasets are always harder to code against, and if this is supposed to create a report, PROC REPORT does this on the fly:&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;also&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Maxim 14. Use PROC TRANSPOSE or PROC REPORT, and be done with it.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;All excellent advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This ought to end any discussion of doing a transpose using SQL. I hope the original poster is paying attention.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 10:20:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752827#M237173</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-08T10:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose data in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752909#M237209</link>
      <description>&lt;P&gt;Just reading the title of this post "transpose data in proc sql" gave me a headache.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given the verbose nature of having to name everything explicitly in SQL and the row nature of normal SQL behavior the question is sort of an extreme version of using a spoon to hammer nails. It may work but you will put a lot of effort into getting it to work in any specific case. Minor changes like adding a single value to one variable will add to the work.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 15:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-transpose-data-in-proc-sql/m-p/752909#M237209</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-08T15:58:46Z</dc:date>
    </item>
  </channel>
</rss>

