<?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: need SAS to analyze data within a group in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182428#M46459</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use HaiKuo's data and partial code .&lt;/P&gt;&lt;P&gt;Your second one is ambiguous. you want all of CHIEF_COMPLAINT be NULL and all of &lt;SPAN style="color: #ffffff; text-align: center; background-color: #6690bc;"&gt;DIAGNOSIS_TEXT&lt;/SPAN&gt; not be NULL ?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;CHIEF_COMPLAINT is null, but &lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit; color: #ffffff; text-align: center; background-color: #6690bc;"&gt;DIAGNOSIS_TEXT&lt;/SPAN&gt; is NOT null - 0&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
infile cards expandtabs;
input (UNIQUE_VISITING_ID&amp;nbsp; PATIENT_CLASS&amp;nbsp;&amp;nbsp; CHIEF_COMPLAINT) (:$20.)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DIAGNOSIS_TEXT &amp;amp; $20.;
cards;
A&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL
A&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; NULL
A&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; NULL
A&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; HEART ATTACK
A&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; HEART ATTACK
B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; shortbreath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL
B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; shortbreath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL
B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; shortbreath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL
B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; SHORTBREATH&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL
C&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CHECK UP&amp;nbsp;&amp;nbsp; DEFICIENT FE
C&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CHECK UP&amp;nbsp;&amp;nbsp; DEFICIENT FE
D&amp;nbsp;&amp;nbsp;&amp;nbsp; U&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL
E&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL
E&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; NULL
E&amp;nbsp;&amp;nbsp;&amp;nbsp; O&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; POOR SURGERY
E&amp;nbsp;&amp;nbsp;&amp;nbsp; O&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; POOR SURGERY
F&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL
F&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL
;
run;

proc sql;
create table x as
 select UNIQUE_VISITING_ID,((sum( DIAGNOSIS_TEXT eq 'NULL') eq count(*)) and
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (sum(CHIEF_COMPLAINT eq 'NULL') eq count(*)) ) as flag1,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((sum( DIAGNOSIS_TEXT ne 'NULL') eq count(*)) and
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (sum(CHIEF_COMPLAINT eq 'NULL') eq count(*)) ) as flag2,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (sum( PATIENT_CLASS eq 'E') ge 1)&amp;nbsp; as flag3,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (sum( PATIENT_CLASS eq 'E') eq 0)&amp;nbsp; as flag4
from have
 group by UNIQUE_VISITING_ID ;
quit;



/*THIS REMOVES GROUP NEVER E*/
PROC SQL;
CREATE TABLE WANT AS
SELECT * FROM HAVE
GROUP BY&amp;nbsp; UNIQUE_VISITING_ID
HAVING SUM(PATIENT_CLASS EQ 'E') &amp;gt;0
;
QUIT;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: xia keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 17 Apr 2014 03:41:48 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2014-04-17T03:41:48Z</dc:date>
    <item>
      <title>need SAS to analyze data within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182423#M46454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin: 0 0 1em; font-size: 14px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;"&gt;I'm trying to analyze some grouped data in SAS 9.3. This is how its structured (not the actual data):&lt;/P&gt;&lt;P style="margin: 0 0 1em; font-size: 14px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;"&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;UNIQUE_VISITING_ID&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;SPAN style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"&gt;PATIENT_CLASS&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;CHIEF_COMPLAINT&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;DIAGNOSIS_TEXT&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;CP&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;CP&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;I&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;CP&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;HEART ATTACK&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;I&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;CP&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;HEART ATTACK&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;SPAN style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"&gt;shortbreath&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;SPAN style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"&gt;shortbreath&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;SPAN style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"&gt;shortbreath&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;SHORTBREATH&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;C&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;I&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;CHECK UP&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;SPAN style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"&gt;DEFICIENT FE&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;C&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;I&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;CHECK UP &lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;SPAN style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"&gt;DEFICIENT FE&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;D&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;U&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;CP&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;O&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;CP&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;SPAN style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"&gt;POOR SURGERY&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;O&lt;/TD&gt;&lt;TD&gt;CP&lt;/TD&gt;&lt;TD&gt;&lt;SPAN style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"&gt;POOR SURGERY&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P style="margin: 0 0 1em; font-size: 14px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;"&gt;With each unique &lt;SPAN style="color: #ffffff; text-align: center; background-color: #6690bc;"&gt;UNIQUE_VISITING_ID&lt;/SPAN&gt; being a single patient visit (so 6 visits total in this set)&lt;/P&gt;&lt;P style="margin: 0 0 1em; font-size: 14px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;"&gt;(please note that the real data is not ordered or sorted in any way)&lt;/P&gt;&lt;P style="margin: 0 0 1em; font-size: 14px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;"&gt;I need to count the number of visits where:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN style="color: #ffffff; text-align: center; background-color: #6690bc;"&gt;DIAGNOSIS_TEXT&lt;/SPAN&gt;and CHIEF_COMPLAINT are always null (never have a real value in there) - 2&lt;/LI&gt;&lt;LI&gt;CHIEF_COMPLAINT is null, but &lt;SPAN style="color: #ffffff; text-align: center; background-color: #6690bc;"&gt;DIAGNOSIS_TEXT&lt;/SPAN&gt; is NOT null - 0&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="color: #ffffff; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; text-align: center; background-color: #6690bc;"&gt;PATIENT_CLASS&lt;/SPAN&gt; is 'E' at least once within the visit - 4&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="color: #ffffff; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; text-align: center; background-color: #6690bc;"&gt;PATIENT_CLASS&lt;/SPAN&gt; class is NEVER 'E' within the visit - 2&lt;/LI&gt;&lt;/UL&gt;&lt;P style="margin: 0 0 1em; font-size: 14px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;"&gt;Plus, how to remove a group where &lt;SPAN style="color: #ffffff; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; text-align: center; background-color: #6690bc;"&gt;PATIENT_CLASS&lt;/SPAN&gt; is never &lt;CODE style="padding: 1px 5px; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"&gt;E&lt;/CODE&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1em; font-size: 14px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;"&gt;Any ideas? I've tried it a few different ways and I worry it's not working like I want it to. Specifically, I'd imagine the two patient class ones should add up to the total number of visits, but they're actually much more than the total &lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://communities.sas.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt;&amp;nbsp; Would really appreciate any help!!&lt;/P&gt;&lt;P style="margin: 0 0 1em; font-size: 14px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;"&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1em; font-size: 14px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;"&gt;----&lt;/P&gt;&lt;P style="margin: 0 0 1em; font-size: 14px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;"&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1em; font-size: 14px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;"&gt;I've tried the following: &lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;PROC&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;SQL&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;TABLE&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ERRORS_&amp;amp;PLACE&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; UNIQUE_VISITING_ID,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(case &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;when&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; (max(DIAGNOSIS_TEXT)is &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;null&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; max(CHIEF_COMPLAINT)is &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;null&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;else&lt;/SPAN&gt; &lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; end) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; FLAG1,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(case &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;when&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(max(DIAGNOSIS_TEXT)is &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;not&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;null&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; max(CHIEF_COMPLAINT)is &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;null&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;else&lt;/SPAN&gt; &lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; end) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; FLAG2,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: black; background-color: white;"&gt;(case &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: blue; background-color: white;"&gt;when&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: black; background-color: white;"&gt; (PATIENT_CLASS) = &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: purple; background-color: white;"&gt;'E'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: blue; background-color: white;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;STRONG style="line-height: 1.5em; color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: blue; background-color: white;"&gt;else&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;STRONG style="line-height: 1.5em; color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: black; background-color: white;"&gt; end) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: blue; background-color: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: black; background-color: white;"&gt; flag3,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: black; background-color: white;"&gt;(case &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: blue; background-color: white;"&gt;when&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: black; background-color: white;"&gt;(PATIENT_CLASS) = &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: purple; background-color: white;"&gt;'E'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: blue; background-color: white;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;STRONG style="line-height: 1.5em; color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: blue; background-color: white;"&gt;else&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;STRONG style="line-height: 1.5em; color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: black; background-color: white;"&gt; end) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: blue; background-color: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Courier New'; color: black; background-color: white;"&gt; flag4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;from &amp;amp;Place&lt;/P&gt;&lt;P&gt;&amp;nbsp; group by UNIQUE_VISITING_ID;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;create table Errors2_&amp;amp;Place&lt;/P&gt;&lt;P&gt;as select distinct(UNIQUE_VISITING_ID),&lt;/P&gt;&lt;P&gt;SUM(FLAG1) AS FLAG1,&lt;/P&gt;&lt;P&gt;SUM(FLAG2) AS FLAG2,&lt;/P&gt;&lt;P&gt;SUM(FLAG3) AS FLAG3,&lt;/P&gt;&lt;P&gt;SUM(FLAG4) AS FLAG4&lt;/P&gt;&lt;P&gt;FROM ERRORS_&amp;amp;PLACE&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;---------------&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have also tried: &lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;PROC&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;SQL&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;TABLE&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; ERRORS_&amp;amp;PLACE&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;AS&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; UNIQUE_VISITING_ID,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;(case &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;when&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; ((DIAGNOSIS_TEXT) is &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;null&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; (CHIEF_COMPLAINT) is &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;null&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; max(DIAGNOSIS_CODE) is &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;null&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;then&lt;/SPAN&gt; &lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;else&lt;/SPAN&gt; &lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; end) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; FLAG1,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;(case &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;when&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;(max(DIAGNOSIS_TEXT) is &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;not&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;null&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; (max(CHIEF_COMPLAINT) is &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;null&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;then&lt;/SPAN&gt; &lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;else&lt;/SPAN&gt; &lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; end) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; FLAG2,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;MAX(case &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;when&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; (PATIENT_CLASS) = &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: purple; background-color: white;"&gt;'E'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;else&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; end) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; flag3,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;MAX(case &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;when&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;(PATIENT_CLASS) = &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: purple; background-color: white;"&gt;'E'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;else&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; end) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: blue; background-color: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt; flag4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;from &amp;amp;Place&lt;/P&gt;&lt;P&gt;&amp;nbsp; group by UNIQUE_VISITING_ID;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;create table Errors2_&amp;amp;Place&lt;/P&gt;&lt;P&gt;as select distinct(UNIQUE_VISITING_ID),&lt;/P&gt;&lt;P&gt;MAX(FLAG1) AS FLAG1,&lt;/P&gt;&lt;P&gt;MAX(FLAG2) AS FLAG2,&lt;/P&gt;&lt;P&gt;MAX(FLAG3) AS FLAG3,&lt;/P&gt;&lt;P&gt;MAX(FLAG4) AS FLAG4&lt;/P&gt;&lt;P&gt;FROM ERRORS_&amp;amp;PLACE&lt;/P&gt;&lt;P&gt;group by UNIQUE_VISITING_ID&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;create table Errors3_&amp;amp;Place&lt;/P&gt;&lt;P&gt;as select distinct(UNIQUE_VISITING_ID),&lt;/P&gt;&lt;P&gt;SUM(FLAG1) AS FLAG1,&lt;/P&gt;&lt;P&gt;SUM(FLAG2) AS FLAG2,&lt;/P&gt;&lt;P&gt;SUM(FLAG3) AS FLAG3,&lt;/P&gt;&lt;P&gt;SUM(FLAG4) AS FLAG4&lt;/P&gt;&lt;P&gt;FROM ERRORS_&amp;amp;PLACE&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 18:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182423#M46454</guid>
      <dc:creator>Farah_Naz</dc:creator>
      <dc:date>2014-04-16T18:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: need SAS to analyze data within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182424#M46455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is your desired output for your sample data?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 18:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182424#M46455</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-04-16T18:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: need SAS to analyze data within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182425#M46456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;UNIQUE_VISITING_ID&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;FLAG1&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;FLAG2&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;FLAG3&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;FLAG4&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;C&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;D&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;E&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;F&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 18:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182425#M46456</guid>
      <dc:creator>Farah_Naz</dc:creator>
      <dc:date>2014-04-16T18:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: need SAS to analyze data within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182426#M46457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;infile&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;cards&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;dlm&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'09'x&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; (UNIQUE_VISITING_ID&amp;nbsp; PATIENT_CLASS&amp;nbsp;&amp;nbsp; CHIEF_COMPLAINT) (:&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: teal; background: white;"&gt;$20.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DIAGNOSIS_TEXT :$&amp;amp;&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;20.&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; HEART ATTACK&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; HEART ATTACK&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; shortbreath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; shortbreath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; shortbreath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; SHORTBREATH&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;C&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CHECK UP&amp;nbsp;&amp;nbsp; DEFICIENT FE&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;C&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CHECK UP&amp;nbsp;&amp;nbsp; DEFICIENT FE&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;D&amp;nbsp;&amp;nbsp;&amp;nbsp; U&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;E&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;E&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;E&amp;nbsp;&amp;nbsp;&amp;nbsp; O&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; POOR SURGERY&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;E&amp;nbsp;&amp;nbsp;&amp;nbsp; O&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; POOR SURGERY&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;F&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;F&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: green; background: white;"&gt;/*THIS GIVES YOU THE COUNTS*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;PROC&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;SQL&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;TABLE&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; COUNT &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; SUM(_FIRST=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; FIRST,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(_SECOND=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; SECOND,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(_THIRD&amp;gt;&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; THIRD,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(_THIRD=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; FORTH&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;FROM&lt;/SPAN&gt; &lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; SUM(DIAGNOSIS_TEXT NE &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'NULL'&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;OR&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; CHIEF_COMPLAINT NE &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'NULL'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; _FIRST, &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: green; background: white;"&gt;/* COUNT =0*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(CHIEF_COMPLAINT NE &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'NULL'&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;OR&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; DIAGNOSIS_TEXT EQ &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'NULL'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; _SECOND,&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: green; background: white;"&gt;/* COUNT =0*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(PATIENT_CLASS EQ &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'E'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; _THIRD, &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: green; background: white;"&gt;/*COUNT &amp;gt;0*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(PATIENT_CLASS EQ &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'E'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; _FORTH &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: green; background: white;"&gt;/* COUNT =0*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; HAVE &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;GROUP&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;BY&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; UNIQUE_VISITING_ID )&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;QUIT&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: green; background: white;"&gt;/*THIS REMOVES GROUP NEVER E*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;PROC&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;SQL&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;TABLE&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; WANT &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; * &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; HAVE&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;GROUP&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;BY&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; UNIQUE_VISITING_ID&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;HAVING&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; SUM(PATIENT_CLASS EQ &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'E'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;) &amp;gt;&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;QUIT&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 19:10:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182426#M46457</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-04-16T19:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: need SAS to analyze data within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182427#M46458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In this case, it is even simpler:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;PROC&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;SQL&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;TABLE&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; WANT &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; UNIQUE_VISITING_ID, &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;NOT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;(SUM(DIAGNOSIS_TEXT NE &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'NULL'&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;OR&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; CHIEF_COMPLAINT NE &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'NULL'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;)) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; FLAG1, &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: green; background: white;"&gt;/* COUNT =0*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;NOT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;(SUM(CHIEF_COMPLAINT NE &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'NULL'&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;OR&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; DIAGNOSIS_TEXT EQ &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'NULL'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;)) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; FLAG2,&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: green; background: white;"&gt;/* COUNT =0*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(PATIENT_CLASS EQ &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'E'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;)&amp;gt;&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; FLAG3 , &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: green; background: white;"&gt;/*COUNT &amp;gt;0*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(PATIENT_CLASS EQ &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'E'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;)=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; FLAG4 &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: green; background: white;"&gt;/* COUNT =0*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; HAVE &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;GROUP&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;BY&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; UNIQUE_VISITING_ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;QUIT&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;Haikuo &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 19:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182427#M46458</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-04-16T19:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: need SAS to analyze data within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182428#M46459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use HaiKuo's data and partial code .&lt;/P&gt;&lt;P&gt;Your second one is ambiguous. you want all of CHIEF_COMPLAINT be NULL and all of &lt;SPAN style="color: #ffffff; text-align: center; background-color: #6690bc;"&gt;DIAGNOSIS_TEXT&lt;/SPAN&gt; not be NULL ?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;CHIEF_COMPLAINT is null, but &lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit; color: #ffffff; text-align: center; background-color: #6690bc;"&gt;DIAGNOSIS_TEXT&lt;/SPAN&gt; is NOT null - 0&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
infile cards expandtabs;
input (UNIQUE_VISITING_ID&amp;nbsp; PATIENT_CLASS&amp;nbsp;&amp;nbsp; CHIEF_COMPLAINT) (:$20.)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DIAGNOSIS_TEXT &amp;amp; $20.;
cards;
A&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL
A&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; NULL
A&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; NULL
A&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; HEART ATTACK
A&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; HEART ATTACK
B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; shortbreath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL
B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; shortbreath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL
B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; shortbreath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL
B&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; SHORTBREATH&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL
C&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CHECK UP&amp;nbsp;&amp;nbsp; DEFICIENT FE
C&amp;nbsp;&amp;nbsp;&amp;nbsp; I&amp;nbsp;&amp;nbsp;&amp;nbsp; CHECK UP&amp;nbsp;&amp;nbsp; DEFICIENT FE
D&amp;nbsp;&amp;nbsp;&amp;nbsp; U&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL
E&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL
E&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; NULL
E&amp;nbsp;&amp;nbsp;&amp;nbsp; O&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; POOR SURGERY
E&amp;nbsp;&amp;nbsp;&amp;nbsp; O&amp;nbsp;&amp;nbsp;&amp;nbsp; CP&amp;nbsp;&amp;nbsp; POOR SURGERY
F&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL
F&amp;nbsp;&amp;nbsp;&amp;nbsp; E&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL NULL
;
run;

proc sql;
create table x as
 select UNIQUE_VISITING_ID,((sum( DIAGNOSIS_TEXT eq 'NULL') eq count(*)) and
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (sum(CHIEF_COMPLAINT eq 'NULL') eq count(*)) ) as flag1,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((sum( DIAGNOSIS_TEXT ne 'NULL') eq count(*)) and
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (sum(CHIEF_COMPLAINT eq 'NULL') eq count(*)) ) as flag2,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (sum( PATIENT_CLASS eq 'E') ge 1)&amp;nbsp; as flag3,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (sum( PATIENT_CLASS eq 'E') eq 0)&amp;nbsp; as flag4
from have
 group by UNIQUE_VISITING_ID ;
quit;



/*THIS REMOVES GROUP NEVER E*/
PROC SQL;
CREATE TABLE WANT AS
SELECT * FROM HAVE
GROUP BY&amp;nbsp; UNIQUE_VISITING_ID
HAVING SUM(PATIENT_CLASS EQ 'E') &amp;gt;0
;
QUIT;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: xia keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Apr 2014 03:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/need-SAS-to-analyze-data-within-a-group/m-p/182428#M46459</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-04-17T03:41:48Z</dc:date>
    </item>
  </channel>
</rss>

