<?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 output single observation in a dataset? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-single-observation-in-a-dataset/m-p/721452#M223615</link>
    <description>&lt;P&gt;I think it's also the observation of ID=05.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
  by id;
run;

data want;
  set have;
  by id;
  if first.id and last.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&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(drop=cnt id2) as
    select * from have 
    left join (select distinct count(*) as cnt, id as id2 
               from have 
               group by id) 
    on have.id=id2
    where cnt=1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 24 Feb 2021 02:32:12 GMT</pubDate>
    <dc:creator>japelin</dc:creator>
    <dc:date>2021-02-24T02:32:12Z</dc:date>
    <item>
      <title>How to output single observation in a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-single-observation-in-a-dataset/m-p/721451#M223614</link>
      <description>&lt;P&gt;How do i output data with one single observation(01,04 in the following)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input ID $ date date9. number;&lt;BR /&gt;format date date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;01 01jan2020 2&lt;BR /&gt;03 05jan2020 11&lt;BR /&gt;05 14jan2019 9&lt;BR /&gt;02 01jan2020 5&lt;BR /&gt;02 14jan2021 4&lt;BR /&gt;02 22jan2021 12&lt;BR /&gt;02 21jan2021 1&lt;BR /&gt;03 13feb2020 21&lt;BR /&gt;04 02feb2020 12&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 02:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-single-observation-in-a-dataset/m-p/721451#M223614</guid>
      <dc:creator>jude1</dc:creator>
      <dc:date>2021-02-24T02:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to output single observation in a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-single-observation-in-a-dataset/m-p/721452#M223615</link>
      <description>&lt;P&gt;I think it's also the observation of ID=05.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
  by id;
run;

data want;
  set have;
  by id;
  if first.id and last.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&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(drop=cnt id2) as
    select * from have 
    left join (select distinct count(*) as cnt, id as id2 
               from have 
               group by id) 
    on have.id=id2
    where cnt=1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 02:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-single-observation-in-a-dataset/m-p/721452#M223615</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-02-24T02:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to output single observation in a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-single-observation-in-a-dataset/m-p/721455#M223617</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table WANT as
  select * 
  from HAVE
  group by ID
  having count(*) = 1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 02:54:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-single-observation-in-a-dataset/m-p/721455#M223617</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-24T02:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to output single observation in a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-single-observation-in-a-dataset/m-p/721463#M223622</link>
      <description>&lt;P&gt;if you dont want to use any PROC like SQL and SORT, then hash object can be used here in just one DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; 
  if _N_=1 then do; 
	declare hash h();
	h.defineKey('ID');
	h.defineData('ndup');
	h.defineDone();
	call missing(ndup); 

	do _i_=1 to nobs;
		set have point=_i_ nobs=nobs; 				
		if h.find()^=0 then do;
			ndup=1;
			h.add();			
		end;
		else do;
			ndup=ndup+1;
			h.replace();			
		end;			
	end;
  end;

  set have;  
  if h.find()=0 and ndup=1 then do;
    drop ndup;  
	output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 04:11:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-single-observation-in-a-dataset/m-p/721463#M223622</guid>
      <dc:creator>LeonCathay</dc:creator>
      <dc:date>2021-02-24T04:11:14Z</dc:date>
    </item>
  </channel>
</rss>

