<?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 unique function in proc sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/unique-function-in-proc-sql/m-p/251359#M56691</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The question is when I run the following code:&lt;/P&gt;&lt;PRE&gt;proc sql;
select household, unique(trip) as trip, sum(exp)&amp;nbsp;
from temp.data
group by household, trip;
quit;&lt;/PRE&gt;&lt;P&gt;SAS pop up the error:&amp;nbsp;Function UNIQUE could not be located. However, when I switched the unique() term to the first and change the code to&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
select unique(trip) as trip, household,  sum(exp)&amp;nbsp;
from temp.data
group by household, trip;
quit;&lt;/PRE&gt;&lt;P&gt;The procedure works normally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So does this mean that unique() function needs to immediately follow select?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 20 Feb 2016 22:44:05 GMT</pubDate>
    <dc:creator>bochen</dc:creator>
    <dc:date>2016-02-20T22:44:05Z</dc:date>
    <item>
      <title>unique function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unique-function-in-proc-sql/m-p/251359#M56691</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The question is when I run the following code:&lt;/P&gt;&lt;PRE&gt;proc sql;
select household, unique(trip) as trip, sum(exp)&amp;nbsp;
from temp.data
group by household, trip;
quit;&lt;/PRE&gt;&lt;P&gt;SAS pop up the error:&amp;nbsp;Function UNIQUE could not be located. However, when I switched the unique() term to the first and change the code to&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
select unique(trip) as trip, household,  sum(exp)&amp;nbsp;
from temp.data
group by household, trip;
quit;&lt;/PRE&gt;&lt;P&gt;The procedure works normally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So does this mean that unique() function needs to immediately follow select?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2016 22:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unique-function-in-proc-sql/m-p/251359#M56691</guid>
      <dc:creator>bochen</dc:creator>
      <dc:date>2016-02-20T22:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: unique function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unique-function-in-proc-sql/m-p/251363#M56692</link>
      <description>&lt;P&gt;Unique in SAS implementation of SQL is analogous to DISTINCT, and it does apply to all columns and is required at the beginning of the SELECT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Keyword: &lt;/SPAN&gt;&lt;A href="http://www.google.com/search?hl=en-us&amp;amp;q=site%3Asupport.sas.com+%22PROC+SQL%22+%22CREATE%20TABLE+STATEMENT%22+UNIQUE" target="_blank"&gt;UNIQUE&lt;/A&gt; &lt;STRONG&gt;Context: [PROC SQL, CREATE TABLE STATEMENT] UNIQUE option&lt;/STRONG&gt; &lt;BR /&gt;&lt;SPAN&gt;[constraint] Specifies that the values of the column must be unique. This constraint is identical to DISTINCT.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A caveat to that is when using in aggregate function such as count:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test5 as
select origin, count(distinct make) as count
from sashelp.cars
group by origin;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Feb 2016 23:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unique-function-in-proc-sql/m-p/251363#M56692</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-20T23:45:05Z</dc:date>
    </item>
  </channel>
</rss>

