<?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: Conditional edition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-edition/m-p/354394#M82909</link>
    <description>&lt;P&gt;Yes, both proposals work well with some adaptations to my case. Thank you.&lt;/P&gt;</description>
    <pubDate>Fri, 28 Apr 2017 10:20:39 GMT</pubDate>
    <dc:creator>soumri</dc:creator>
    <dc:date>2017-04-28T10:20:39Z</dc:date>
    <item>
      <title>Conditional edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-edition/m-p/353592#M82553</link>
      <description>&lt;P&gt;Hello dear friends;&lt;BR /&gt;I have a database of the form:&lt;/P&gt;&lt;P&gt;ID T AN OBS;&lt;BR /&gt;(ID = Individual ID, T = Team, AN = Year of Control and OBS = Observation);&lt;BR /&gt;I want to make an edition so as to keep only the teams with at least 3 individuals checked each year of control. Not necessarily the same individuals must be present every year.&lt;BR /&gt;NB * the number of individuals in my base is more than 800 miles,&lt;BR /&gt;The number of teams exceeds 3500&lt;BR /&gt;The number of years of checks is equal to 15.&lt;BR /&gt;I used "ODS" and the program runs well but I think there is another method less burdensome.&lt;BR /&gt;Thank you for helping me.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 09:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-edition/m-p/353592#M82553</guid>
      <dc:creator>soumri</dc:creator>
      <dc:date>2017-04-26T09:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-edition/m-p/353593#M82554</link>
      <description>&lt;P&gt;Well, not sure how you used "ODS" to get a result - that is for creating output elements e.g PDF files?&lt;/P&gt;
&lt;P&gt;Assuming your data is sorted (and you haven't provided any test data):&lt;/P&gt;
&lt;PRE&gt;data want;
&amp;nbsp; set have;
&amp;nbsp; retain cnt;
&amp;nbsp; by id t an;
&amp;nbsp; if first.t then cnt=1;
&amp;nbsp; else cnt=cnt+1;
&amp;nbsp; if cnt=3 then output;
run;&lt;/PRE&gt;
&lt;P&gt;What does this do. &amp;nbsp;Well on the first time year in id is encounterd the counter variable gets set to 1, then every row after that the counter is incremented by 1. &amp;nbsp;Only when counter is 3 will therecord output, so you will get one record per id/year when counter hits 3 - i.e. it has 3 records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 09:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-edition/m-p/353593#M82554</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-26T09:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-edition/m-p/353598#M82556</link>
      <description>&lt;P&gt;First, create a table for each team and year:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table intermediate as
select t, an, count(distinct id) as individuals
from have
group by t, an
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Next, extract only those teams that always exceed the count of 2:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select distinct t
from intermediate
where t not in (select distinct t from intermediate where individuals &amp;lt; 3)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Given the size of your dataset, a data step method might be better:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort
  data=have (keep=id t an)
  out=int1
  nodupkey
;
by t an id;
run;

data int2 (keep=t);
set int1;
by t an;
if first.an then count = 0;
count + 1;
if last.an and count &amp;lt; 3 then output;
run;

data want;
merge
  int1 (in=a)
  int2 (in=b)
;
by t;
if not b;
run;

proc sort data=want nodupkey;
by t;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2017 09:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-edition/m-p/353598#M82556</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-26T09:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-edition/m-p/354373#M82904</link>
      <description>&lt;P&gt;Thanks for the solution.&lt;BR /&gt;The basic type I have is of the longitudinal type, so there are measures that repeat over time for the same ID during the same NA. If I understand correctly, with this code, we will have the Ts which also repeat as a function of time for the same ID and therefore it will return the number of T and not the number of IDs by T by AN (which I look for)&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 09:38:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-edition/m-p/354373#M82904</guid>
      <dc:creator>soumri</dc:creator>
      <dc:date>2017-04-28T09:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-edition/m-p/354394#M82909</link>
      <description>&lt;P&gt;Yes, both proposals work well with some adaptations to my case. Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 10:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-edition/m-p/354394#M82909</guid>
      <dc:creator>soumri</dc:creator>
      <dc:date>2017-04-28T10:20:39Z</dc:date>
    </item>
  </channel>
</rss>

