<?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: Find last Cycle for subject and check whether all cycles before that are present or not in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-last-Cycle-for-subject-and-check-whether-all-cycles-before/m-p/776141#M246782</link>
    <description>&lt;P&gt;Create a template with all subjects and cycles.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data required;
input cycle $;
datalines;
C1
C2
C3
C4
C5
C6
C7
;

proc sql,
create table template as
  select distinct a.subject, b.cycle
  from have a, required b
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use this in a MERGE to determine the missing rows.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  have (in=h)
  template
;
by subject cycle;
if not h;
keep subject cycle;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, supply example data in usable form (data step with datalines, posted in a code box).&lt;/P&gt;</description>
    <pubDate>Mon, 25 Oct 2021 08:10:28 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-10-25T08:10:28Z</dc:date>
    <item>
      <title>Find last Cycle for subject and check whether all cycles before that are present or not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-last-Cycle-for-subject-and-check-whether-all-cycles-before/m-p/776138#M246780</link>
      <description>Eg.&lt;BR /&gt;Required cycles : C1, C2, C3, C4, C5, C6 C7&lt;BR /&gt;If Sub1 has C1, C2, C5 then C3, C4 missing for Sub1 should be in the output&lt;BR /&gt;If Sub2 has C1, C2, C3, C7 then C4, C5, C6 missing for Sub2 should be in the output</description>
      <pubDate>Mon, 25 Oct 2021 07:50:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-last-Cycle-for-subject-and-check-whether-all-cycles-before/m-p/776138#M246780</guid>
      <dc:creator>PK06</dc:creator>
      <dc:date>2021-10-25T07:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: Find last Cycle for subject and check whether all cycles before that are present or not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-last-Cycle-for-subject-and-check-whether-all-cycles-before/m-p/776140#M246781</link>
      <description>Dataset&lt;BR /&gt;Sub1 C1&lt;BR /&gt;Sub1 C2&lt;BR /&gt;Sub1 C5&lt;BR /&gt;Sub2 C1&lt;BR /&gt;Sub2 C2&lt;BR /&gt;Sub2 C3&lt;BR /&gt;Sub3 C7&lt;BR /&gt;&lt;BR /&gt;Expected Output :&lt;BR /&gt;Sub1 C3&lt;BR /&gt;Sub1 C4&lt;BR /&gt;Sub2 C4&lt;BR /&gt;Sub2 C5&lt;BR /&gt;Sub2 C6</description>
      <pubDate>Mon, 25 Oct 2021 08:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-last-Cycle-for-subject-and-check-whether-all-cycles-before/m-p/776140#M246781</guid>
      <dc:creator>PK06</dc:creator>
      <dc:date>2021-10-25T08:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Find last Cycle for subject and check whether all cycles before that are present or not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-last-Cycle-for-subject-and-check-whether-all-cycles-before/m-p/776141#M246782</link>
      <description>&lt;P&gt;Create a template with all subjects and cycles.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data required;
input cycle $;
datalines;
C1
C2
C3
C4
C5
C6
C7
;

proc sql,
create table template as
  select distinct a.subject, b.cycle
  from have a, required b
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use this in a MERGE to determine the missing rows.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  have (in=h)
  template
;
by subject cycle;
if not h;
keep subject cycle;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, supply example data in usable form (data step with datalines, posted in a code box).&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 08:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-last-Cycle-for-subject-and-check-whether-all-cycles-before/m-p/776141#M246782</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-25T08:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Find last Cycle for subject and check whether all cycles before that are present or not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-last-Cycle-for-subject-and-check-whether-all-cycles-before/m-p/776175#M246804</link>
      <description>&lt;PRE&gt;data required;
input cycle $;
datalines;
C1
C2
C3
C4
C5
C6
C7
;

data have;
input subject $ cycle $;
cards;
Sub1 C1
Sub1 C2
Sub1 C5
Sub2 C1
Sub2 C2
Sub2 C3
Sub2 C7
;

proc sql;
create table temp as
select subject,
 min(input(compress(cycle,,'kd'),best.)) as min,
 max(input(compress(cycle,,'kd'),best.)) as max
 from have
  group by subject;
quit;
data temp2;
 set temp;
 length cycle $ 20;
 do i=min to max;
   cycle=cats('C',i);output;
 end;
 keep subject cycle;
run;
proc sql;
create table want as
select * from temp2
except 
select * from have;
quit;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Oct 2021 12:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-last-Cycle-for-subject-and-check-whether-all-cycles-before/m-p/776175#M246804</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-10-25T12:02:02Z</dc:date>
    </item>
  </channel>
</rss>

