<?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 Proc SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75561#M21920</link>
    <description>Hi. I have a large SAS dataset and I am using Proc SQL. This is a sample data set from table1. How can I get table 2 from table1 to have one unique record for each person:&lt;BR /&gt;
Table 1				&lt;BR /&gt;
Name	Color	Age	Enrolled	&lt;BR /&gt;
Jo	red	24	Y	&lt;BR /&gt;
Jo	blue	24	Y	&lt;BR /&gt;
Ray	red	31	Y	&lt;BR /&gt;
MIke	blue	28	N	&lt;BR /&gt;
&lt;BR /&gt;
Table 2				&lt;BR /&gt;
Name	Red	Blue	Age	Enrolled&lt;BR /&gt;
Jo	red	blue	24	Y&lt;BR /&gt;
Ray	red		31	Y&lt;BR /&gt;
Mike		blue	28	N&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
    <pubDate>Fri, 16 Apr 2010 14:38:23 GMT</pubDate>
    <dc:creator>MLS</dc:creator>
    <dc:date>2010-04-16T14:38:23Z</dc:date>
    <item>
      <title>Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75561#M21920</link>
      <description>Hi. I have a large SAS dataset and I am using Proc SQL. This is a sample data set from table1. How can I get table 2 from table1 to have one unique record for each person:&lt;BR /&gt;
Table 1				&lt;BR /&gt;
Name	Color	Age	Enrolled	&lt;BR /&gt;
Jo	red	24	Y	&lt;BR /&gt;
Jo	blue	24	Y	&lt;BR /&gt;
Ray	red	31	Y	&lt;BR /&gt;
MIke	blue	28	N	&lt;BR /&gt;
&lt;BR /&gt;
Table 2				&lt;BR /&gt;
Name	Red	Blue	Age	Enrolled&lt;BR /&gt;
Jo	red	blue	24	Y&lt;BR /&gt;
Ray	red		31	Y&lt;BR /&gt;
Mike		blue	28	N&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
      <pubDate>Fri, 16 Apr 2010 14:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75561#M21920</guid>
      <dc:creator>MLS</dc:creator>
      <dc:date>2010-04-16T14:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75562#M21921</link>
      <description>Use DISTINCT with your SELECT and column/variable list.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic/post:&lt;BR /&gt;
&lt;BR /&gt;
proc sql select distinct site:sas.com</description>
      <pubDate>Fri, 16 Apr 2010 14:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75562#M21921</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-04-16T14:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75563#M21922</link>
      <description>Please notice that column headers from table1 to table 2 are different.</description>
      <pubDate>Fri, 16 Apr 2010 14:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75563#M21922</guid>
      <dc:creator>MLS</dc:creator>
      <dc:date>2010-04-16T14:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75564#M21923</link>
      <description>couldn't you just join table1 where color=red to table1 where color=blue?</description>
      <pubDate>Fri, 16 Apr 2010 15:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75564#M21923</guid>
      <dc:creator>RickM</dc:creator>
      <dc:date>2010-04-16T15:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75565#M21924</link>
      <description>Is this the query you suggest? (Table2 has 2 columns that Table1 doesn't have them)&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
&lt;BR /&gt;
	create table work.Table2 as&lt;BR /&gt;
(Select distinct &lt;BR /&gt;
a.Name,&lt;BR /&gt;
a.Age,&lt;BR /&gt;
a.Enrolled,&lt;BR /&gt;
Red,&lt;BR /&gt;
Blue&lt;BR /&gt;
from work.Table1 a join work.Table1 a&lt;BR /&gt;
if  a.Color = 'red' then Red = 'red' &lt;BR /&gt;
	else (if a.Color = 'blue' then Blue = 'blue') end if );&lt;BR /&gt;
quit;</description>
      <pubDate>Fri, 16 Apr 2010 15:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75565#M21924</guid>
      <dc:creator>MLS</dc:creator>
      <dc:date>2010-04-16T15:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75566#M21925</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
I believe the code below does what you're looking for:&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  infile datalines truncover;&lt;BR /&gt;
  input Name $ Color $ Age Enrolled $ ;&lt;BR /&gt;
  datalines;&lt;BR /&gt;
Jo red 24 Y &lt;BR /&gt;
Jo blue 24 Y &lt;BR /&gt;
Ray red 31 Y &lt;BR /&gt;
MIke blue 28 N &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select &lt;BR /&gt;
    name&lt;BR /&gt;
    ,max(case(color) when ('blue') then color else '' end) as blue&lt;BR /&gt;
    ,max(case(color) when ('red')  then color else '' end) as red&lt;BR /&gt;
    ,age&lt;BR /&gt;
    ,enrolled&lt;BR /&gt;
    from have&lt;BR /&gt;
  group by name,age,enrolled&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;		&lt;BR /&gt;
&lt;BR /&gt;
This example covers the cases 'red' and 'blue' - but what if one doesn't know for sure what colours will be in the data.&lt;BR /&gt;
&lt;BR /&gt;
I thinks this is a case where an approach using PROC TRANSPOSE would allow a more dynamic solution.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Sun, 18 Apr 2010 11:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/75566#M21925</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-04-18T11:40:29Z</dc:date>
    </item>
  </channel>
</rss>

