<?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 to count positive and negative PID's in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827810#M326982</link>
    <description>&lt;P&gt;Why isn't count = 2 for treatment A in Negative? Both PID = 101 and PID = 102 has all negative values.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Aug 2022 11:39:35 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-08-09T11:39:35Z</dc:date>
    <item>
      <title>need to count positive and negative PID's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827804#M326977</link>
      <description>&lt;P&gt;I need to count positive and negative PID's based on trt like below.&lt;/P&gt;
&lt;TABLE width="279"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="87"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64"&gt;A&lt;/TD&gt;
&lt;TD width="64"&gt;B&lt;/TD&gt;
&lt;TD width="64"&gt;C&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Positive&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Negative&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Positive is when PID is negative at BL="Y" and then changes to positive later at anytime. and negative means PID is negative everywhere.&lt;/P&gt;
&lt;P&gt;Can any one help me how to do this.&lt;/P&gt;
&lt;P&gt;Sample data&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA WORK.ADA_0001;
    LENGTH
        PID                8
        result           $ 8
        trt              $ 1
        Visit              8
        BL               $ 1 ;
    FORMAT
        PID              BEST12.
        result           $CHAR8.
        trt              $CHAR1.
        Visit            BEST12.
        BL               $CHAR1. ;
    INFORMAT
        PID              BEST12.
        result           $CHAR8.
        trt              $CHAR1.
        Visit            BEST12.
        BL               $CHAR1. ;
    INFILE DATALINES4
        DLM='7F'x
        MISSOVER
        DSD ;
    INPUT
        PID              : BEST32.
        result           : $CHAR8.
        trt              : $CHAR1.
        Visit            : BEST32.
        BL               : $CHAR1. ;
DATALINES4;
101&amp;#127;NEGATIVE&amp;#127;A&amp;#127;1&amp;#127;Y
102&amp;#127;NEGATIVE&amp;#127;A&amp;#127;1&amp;#127;Y
102&amp;#127;NEGATIVE&amp;#127;A&amp;#127;2&amp;#127; 
103&amp;#127;NEGATIVE&amp;#127;B&amp;#127;1&amp;#127;Y
103&amp;#127;NEGATIVE&amp;#127;B&amp;#127;2&amp;#127; 
103&amp;#127;POSITIVE&amp;#127;B&amp;#127;3&amp;#127; 
103&amp;#127;POSITIVE&amp;#127;B&amp;#127;4&amp;#127; 
104&amp;#127;NEGATIVE&amp;#127;C&amp;#127;1&amp;#127;Y
104&amp;#127;NEGATIVE&amp;#127;C&amp;#127;2&amp;#127; 
104&amp;#127;NEGATIVE&amp;#127;C&amp;#127;3&amp;#127; 
105&amp;#127;NEGATIVE&amp;#127;C&amp;#127;1&amp;#127;Y
105&amp;#127;NEGATIVE&amp;#127;C&amp;#127;2&amp;#127; 
105&amp;#127;POSITIVE&amp;#127;C&amp;#127;3&amp;#127; 
;;;;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Aug 2022 10:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827804#M326977</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2022-08-09T10:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: need to count positive and negative PID's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827805#M326978</link>
      <description>&lt;P&gt;Does this logic has to hold wihtin each&amp;nbsp;&lt;SPAN&gt;PID&amp;nbsp;?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 10:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827805#M326978</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-09T10:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: need to count positive and negative PID's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827806#M326979</link>
      <description>&lt;P&gt;Within each PID if BL="Y" is negative and within PID if there is any positve then that PID will be positive and if all are negative then that PID comes under negative. Then i need to count number of positives and negatives under trt&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 11:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827806#M326979</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2022-08-09T11:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: need to count positive and negative PID's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827810#M326982</link>
      <description>&lt;P&gt;Why isn't count = 2 for treatment A in Negative? Both PID = 101 and PID = 102 has all negative values.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 11:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827810#M326982</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-09T11:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: need to count positive and negative PID's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827811#M326983</link>
      <description>&lt;P&gt;sorry my mistake. it is 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="279"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="87"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64"&gt;A&lt;/TD&gt;
&lt;TD width="64"&gt;B&lt;/TD&gt;
&lt;TD width="64"&gt;C&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Positive&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Negative&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 09 Aug 2022 11:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827811#M326983</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2022-08-09T11:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: need to count positive and negative PID's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827814#M326985</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ADA_0001;
input PID result $ trt $ Visit BL $;
infile datalines missover;
datalines;
101 NEGATIVE A 1 Y
102 NEGATIVE A 1 Y
102 NEGATIVE A 2  
103 NEGATIVE B 1 Y
103 NEGATIVE B 2  
103 POSITIVE B 3  
103 POSITIVE B 4  
104 NEGATIVE C 1 Y
104 NEGATIVE C 2  
104 NEGATIVE C 3  
105 NEGATIVE C 1 Y
105 NEGATIVE C 2  
105 POSITIVE C 3  
;

data temp;
   dp = 0;
   dn = 0;
   do until (last.PID);
      set ADA_0001;
      by PID;
      if result = 'NEGATIVE' and BL = 'Y' then dp = 1;
      if result = 'POSITIVE' then dn = 1;
      if result = 'POSITIVE' and dp = 1 then do;
         cp = 1;
         dp = 0;
      end;
      else cp = .;
      if last.PID and dn = 0 then cn = 1;
      output;
   end;
run;

Proc tabulate data = temp;
   class trt result;
   Var cn cp;
   tables (cn='Negative' cp='Positive')*sum=''*f=8.
         , trt='';
Run;&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;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PeterClemmensen_0-1660046870958.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74277iFC6782B24AC02EF0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PeterClemmensen_0-1660046870958.png" alt="PeterClemmensen_0-1660046870958.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 12:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827814#M326985</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-09T12:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: need to count positive and negative PID's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827825#M326989</link>
      <description>&lt;P&gt;Thanks, It works. I need to transpose again as proc tabulate out= option doesnt transpose the output right?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 12:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827825#M326989</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2022-08-09T12:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: need to count positive and negative PID's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827827#M326990</link>
      <description>&lt;P&gt;Do you need the result as a data set or as a report?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 12:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827827#M326990</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-09T12:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: need to count positive and negative PID's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827828#M326991</link>
      <description>&lt;P&gt;As dataset&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 12:50:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827828#M326991</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2022-08-09T12:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: need to count positive and negative PID's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827846#M326999</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ADA_0001;
input PID result $ trt $ Visit BL $;
infile datalines missover;
datalines;
101 NEGATIVE A 1 Y
102 NEGATIVE A 1 Y
102 NEGATIVE A 2  
103 NEGATIVE B 1 Y
103 NEGATIVE B 2  
103 POSITIVE B 3  
103 POSITIVE B 4  
104 NEGATIVE C 1 Y
104 NEGATIVE C 2  
104 NEGATIVE C 3  
105 NEGATIVE C 1 Y
105 NEGATIVE C 2  
105 POSITIVE C 3  
;
data temp;
do i=1 by 1 until(last.trt);
 set ADA_0001;
 by PID trt;
 if result='POSITIVE' then has_p=1;
 if result='NEGATIVE' and BL='Y' then do;flag=1;_i=i;end;
end;
if not has_p then n_p='NEGATIVE';
do j=1 by 1 until(last.trt);
 set ADA_0001;
 by PID trt;
 if flag and j&amp;gt;_i and result='POSITIVE' then n_p='POSITIVE';
end;
keep n_p trt;
run;

proc freq data=temp noprint;
table n_p*trt/out=temp1 ;
run;

proc transpose data=temp1 out=want(drop=_:);
by n_p;
id trt;
var count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Aug 2022 13:33:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-count-positive-and-negative-PID-s/m-p/827846#M326999</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-08-09T13:33:11Z</dc:date>
    </item>
  </channel>
</rss>

