<?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: Using Proc sql select distinct and keep in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Using-Proc-sql-select-distinct-and-keep/m-p/698462#M25501</link>
    <description>&lt;P&gt;The KEEP= option means that the variable you want, STRUCTURE_NUMBER_008, is not available.&lt;/P&gt;
&lt;P&gt;Put it on the keep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or more in line with SQL behavior perhaps:&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table SUP.IDNBI_PSC_FILES as
select distinct STRUCTURE_NUMBER_008,STRUCTURE_KIND_043A, OWNER_022
from SUP.IDNBI_PSC_SUPER ;
quit;&lt;/PRE&gt;</description>
    <pubDate>Thu, 12 Nov 2020 18:05:27 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-11-12T18:05:27Z</dc:date>
    <item>
      <title>Using Proc sql select distinct and keep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-Proc-sql-select-distinct-and-keep/m-p/698452#M25500</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a set of bridge data with different variables such as: bridge number (STRUCTURE_NUMBER_008), kind(STRUCTURE_KIND_043A ), owner(OWNER_022), inspection years, etc.&lt;/P&gt;
&lt;P&gt;Because inspection year differs I have multiple rows of the same bridge number. I want to do a stratified sample selection base on kind and owner; However, I don't want my sample selection to select the same bridge given the repeated row of the same bridge number.&lt;/P&gt;
&lt;P&gt;I was thinking of selecting one bridge number first in my data using proc sql and select distinct, but while doing that I want to keep the variable&amp;nbsp;kind(STRUCTURE_KIND_043A ), owner(OWNER_022) so I can do the stratified sampling later on.&lt;/P&gt;
&lt;P&gt;I am having error with my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table SUP.IDNBI_PSC_FILES as&lt;BR /&gt;select distinct STRUCTURE_NUMBER_008&lt;BR /&gt;from SUP.IDNBI_PSC_SUPER (KEEP=STRUCTURE_KIND_043A OWNER_022);&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;log error&lt;/P&gt;
&lt;P&gt;42 proc sql;&lt;BR /&gt;43 create table SUP.IDNBI_PSC_FILES as&lt;BR /&gt;44 select distinct STRUCTURE_NUMBER_008&lt;BR /&gt;45 from SUP.IDNBI_PSC_SUPER (KEEP=STRUCTURE_KIND_043A OWNER_022);&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: STRUCTURE_NUMBER_008.&lt;BR /&gt;46 quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 17:29:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-Proc-sql-select-distinct-and-keep/m-p/698452#M25500</guid>
      <dc:creator>Blandine</dc:creator>
      <dc:date>2020-11-12T17:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc sql select distinct and keep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-Proc-sql-select-distinct-and-keep/m-p/698462#M25501</link>
      <description>&lt;P&gt;The KEEP= option means that the variable you want, STRUCTURE_NUMBER_008, is not available.&lt;/P&gt;
&lt;P&gt;Put it on the keep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or more in line with SQL behavior perhaps:&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table SUP.IDNBI_PSC_FILES as
select distinct STRUCTURE_NUMBER_008,STRUCTURE_KIND_043A, OWNER_022
from SUP.IDNBI_PSC_SUPER ;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Nov 2020 18:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-Proc-sql-select-distinct-and-keep/m-p/698462#M25501</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-12T18:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc sql select distinct and keep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-Proc-sql-select-distinct-and-keep/m-p/698482#M25511</link>
      <description>&lt;P&gt;I would suggest to keep only the last inspection for each bridge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table SUP.IDNBI_PSC_FILES as
select 
	STRUCTURE_NUMBER_008,
	STRUCTURE_KIND_043A, 
	OWNER_022,
	inspectionYear
from SUP.IDNBI_PSC_SUPER
group by&amp;nbsp;STRUCTURE_NUMBER_008
having  inspectionYear = max(inspectionYear) ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Replace inspectionYear by the appropriate name. Untested.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 18:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-Proc-sql-select-distinct-and-keep/m-p/698482#M25511</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-11-12T18:58:02Z</dc:date>
    </item>
  </channel>
</rss>

