<?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: Flagging all the records within a id if atleast one record meets the predefined criterion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860104#M339799</link>
    <description>&lt;P&gt;Thank you so much for the earlier response , just to add one more detail to my question my criterion is based on one test i.e ALT and if that test is not available for a ID Then the critfl should be left blank and not as "N".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your response is appreciated.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Feb 2023 10:11:27 GMT</pubDate>
    <dc:creator>sandhya88</dc:creator>
    <dc:date>2023-02-22T10:11:27Z</dc:date>
    <item>
      <title>Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860035#M339761</link>
      <description>Predefined criteria is flag the records for the id as Y if atleast one record with pstbsfl have result &amp;gt;=4*baseresult.&lt;BR /&gt;Data have;&lt;BR /&gt;Input Id visitn testcd result baseresult basefl pstbsfl&lt;BR /&gt;&lt;BR /&gt;1 1 ALT 4 2 . Y&lt;BR /&gt;1 2 ALT 8 2 . Y&lt;BR /&gt;1 0 ALT 2 2 Y .&lt;BR /&gt;1 1 AST 2 2 . Y&lt;BR /&gt;&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Data want;&lt;BR /&gt;Id visitn testcd result baseresult basefl pstbsfl critfl&lt;BR /&gt;&lt;BR /&gt;1 1 ALT 4 2 . Y Y&lt;BR /&gt;1 2 ALT 8 2 . Y Y&lt;BR /&gt;1 0 ALT 2 2 Y . Y&lt;BR /&gt;1 1 AST 2 2 Y . Y&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;The logic here is that as the id 1 is having atleast one record where result is 4* baseresult value ( visitn=2) I want to flag all the records for that id as critfl eq ‘Y’&lt;BR /&gt;&lt;BR /&gt;Your response is appreciated.&lt;BR /&gt;&lt;BR /&gt;Please help&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Feb 2023 22:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860035#M339761</guid>
      <dc:creator>sandhya88</dc:creator>
      <dc:date>2023-02-21T22:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860051#M339769</link>
      <description>&lt;P&gt;You can use count(*) on your have dataset with the condition and assign flag accordingly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	Input Id visitn testcd $ result baseresult basefl $  pstbsfl $;
	datalines;

1 1 ALT 4 2 . Y
1 2 ALT 8 2 . Y
1 0 ALT 2 2 Y .
1 1 AST 2 2 . Y

;
run;

/* count how many records do you have with your if condition */
proc sql;
	select count(*) into:cnt_flg from want where result &amp;gt;=4*baseresult;
	%put cnt_flg= &amp;amp;cnt_flg;
quit;

/* flag Y/N on critfl */
data want;
	set have;

	if &amp;amp;cnt_flg &amp;gt;=1 then
		critfl='Y';
	else
		critfl='N';

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MayurJadhav_0-1677022518071.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80690i7C94C621FC661251/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MayurJadhav_0-1677022518071.png" alt="MayurJadhav_0-1677022518071.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 23:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860051#M339769</guid>
      <dc:creator>MayurJadhav</dc:creator>
      <dc:date>2023-02-21T23:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860094#M339791</link>
      <description>&lt;P&gt;Make sure the data is sorted by ID, and then this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  if 0 then set have; /* just to get same order of variables */                                                                         
  critfl='N';                                                                                                                           
  do until(last.id);                                                                                                                    
    set have;                                                                                                                           
    by id;                                                                                                                              
    if result&amp;gt;=4*baseresult then                                                                                                        
      critfl='Y';                                                                                                                       
    end;                                                                                                                                
  do until(last.id);                                                                                                                    
    set have;                                                                                                                           
    by id;                                                                                                                              
    output;                                                                                                                             
    end;                                                                                                                                
run;             
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Feb 2023 08:53:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860094#M339791</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-02-22T08:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860104#M339799</link>
      <description>&lt;P&gt;Thank you so much for the earlier response , just to add one more detail to my question my criterion is based on one test i.e ALT and if that test is not available for a ID Then the critfl should be left blank and not as "N".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your response is appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 10:11:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860104#M339799</guid>
      <dc:creator>sandhya88</dc:creator>
      <dc:date>2023-02-22T10:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860108#M339802</link>
      <description>&lt;P&gt;I do not quite understand your question, could you give some example data?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 10:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860108#M339802</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-02-22T10:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860111#M339804</link>
      <description>&lt;P&gt;Data have;&lt;/P&gt;&lt;P&gt;input id visitn test result baseresult basefl postbasefl;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 1&amp;nbsp; ALT&amp;nbsp; 12&amp;nbsp; 3&amp;nbsp; . Y&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 2&amp;nbsp; AST&amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; .Y&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 1&amp;nbsp; AST&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp;1&amp;nbsp; Y .&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data want;&lt;/P&gt;&lt;P&gt;input id visitn test result baseresult basefl postbasefl critfl;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 1&amp;nbsp; ALT&amp;nbsp; 12&amp;nbsp; 3&amp;nbsp; . Y Y&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 2&amp;nbsp; AST&amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; .Y&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 1&amp;nbsp; AST&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp;1&amp;nbsp; Y .&amp;nbsp; .&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;For the ID 2 as we dont see any ALT at all that satisfies the predefined criteria result&amp;gt;=4*baseresult i want to see CRITFL as missing for the ID throughout.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PREDEFINED CRITERION: If any postbasefl result of an ID with ALT Is ge 4*baseresult then flag all the records for that ID or if postbasefl for the ID for ALT is missing then leave a null value in CRITFL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully I am a bit clear now&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THANKS ALOT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 10:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860111#M339804</guid>
      <dc:creator>sandhya88</dc:creator>
      <dc:date>2023-02-22T10:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860116#M339805</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  if 0 then set have; /* just to get same order of variables */                                                                         
  do until(last.id);                                                                                                                    
    set have;                                                                                                                           
    by id;                                                                                                                              
    if testcd='ALT' then do;                                                                                                            
      if result&amp;gt;=4*baseresult then                                                                                                      
        critfl='Y';                                                                                                                     
      else if critfl=' ' then                                                                                                           
        critfl='N';                                                                                                                     
      end;                                                                                                                              
    end;                                                                                                                                
  do until(last.id);                                                                                                                    
    set have;                                                                                                                           
    by id;                                                                                                                              
    output;                                                                                                                             
    end;                                                                                                                                
run;        
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Feb 2023 10:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860116#M339805</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-02-22T10:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860120#M339806</link>
      <description>SO THE CRITFL SHOULD BE "Y" if there is any postbasefl record for the ID with ALT Result&amp;gt;=4*baseresult.&lt;BR /&gt;2.CRITFL should be "N" if there is no postbasefl record for the ID with ALT result NOT ge baseresult.&lt;BR /&gt;3.CRITFl should be "" (missing) if the ID Doesnt have any postbasefl record for the ALT test even if it has AST test.&lt;BR /&gt;&lt;BR /&gt;The above response made the values NULL When the CRITFL should be "N".&lt;BR /&gt;&lt;BR /&gt;Thanks once again for your prompt response.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Feb 2023 11:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860120#M339806</guid>
      <dc:creator>sandhya88</dc:creator>
      <dc:date>2023-02-22T11:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860135#M339817</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 Input Id visitn testcd $ result baseresult basefl $  pstbsfl $;
 datalines;
1 1 ALT 4 2 . Y
1 2 ALT 8 2 . Y
1 0 ALT 2 2 Y .
1 1 AST 2 2 . Y
;
run;

proc sql;
create table want as
select *,ifc(max(result&amp;gt;=4*baseresult),'Y','N') as critfl
 from have
  group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Feb 2023 11:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860135#M339817</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-02-22T11:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860139#M339818</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;thanks for your response the response is not giving NULL values for the ID If the ID Doesnt have any postbaseresult record for ALT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks alot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 12:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860139#M339818</guid>
      <dc:creator>sandhya88</dc:creator>
      <dc:date>2023-02-22T12:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860140#M339819</link>
      <description>these are my conditions to flag the CRITFL.&lt;BR /&gt;SO THE CRITFL SHOULD BE "Y" if there is any postbasefl record for the ID with ALT Result&amp;gt;=4*baseresult.&lt;BR /&gt;2.CRITFL should be "N" if there is no postbasefl record for the ID with ALT result NOT ge baseresult.&lt;BR /&gt;3.CRITFl should be "" (missing) if the ID Doesnt have any postbasefl record for the ALT test even if it has AST test.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Feb 2023 12:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860140#M339819</guid>
      <dc:creator>sandhya88</dc:creator>
      <dc:date>2023-02-22T12:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860148#M339822</link>
      <description>&lt;P&gt;OK.Try this one.(I did not test it)&lt;/P&gt;
&lt;P&gt;P.S. You'd better post more output data to explain your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 Input Id visitn testcd $ result baseresult basefl $  pstbsfl $;
 datalines;
1 1 ALT 4 2 . Y
1 2 ALT 8 2 . Y
1 0 ALT 2 2 Y .
1 1 AST 2 2 . Y
;
run;

proc sql;
create table want as
select *,
case when max(pstbsfl='Y' and testcd='ALT' and result&amp;gt;=4*baseresult) then 'Y'
     when max(pstbsfl='Y' and testcd='ALT' and result&amp;lt;baseresult)=0 then 'N'
     when max(pstbsfl='Y' and testcd='ALT')=0 then ' '
else 'X' end as critfl
 from have
  group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Feb 2023 12:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860148#M339822</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-02-22T12:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860152#M339823</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your response again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data want;&lt;/P&gt;&lt;P&gt;input id visitn test result baseresult basefl postbasefl critfl;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 1&amp;nbsp; ALT&amp;nbsp; 12&amp;nbsp; 3&amp;nbsp; . Y Y&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 2&amp;nbsp; AST&amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; .Y&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 1&amp;nbsp; AST&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp;1&amp;nbsp; Y .&amp;nbsp; .&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2&amp;nbsp; AST&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp;1 . Y .&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;For the ID 2 as we dont see any ALT at all that satisfies the predefined criteria result&amp;gt;=4*baseresult i want to see CRITFL as missing for the ID throughout.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PREDEFINED CRITERION: If any postbasefl result of an ID with ALT Is ge 4*baseresult then flag all the records for that ID or if postbasefl for the ID for ALT is missing then leave a null value in CRITFL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the above response has populated "X' for CRITFL when none of the pstblfl records has result&amp;gt;=4*baseresult but whereas we need to see "N",please have a look the want dataset above .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 12:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860152#M339823</guid>
      <dc:creator>sandhya88</dc:creator>
      <dc:date>2023-02-22T12:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860419#M339903</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
It is hard to understand your logic.
Can you post tree example/output corresponding to your three conditions?
*/
data have;
 Input Id visitn testcd $ result baseresult basefl $  pstbsfl $;
 datalines;
1  1  ALT  12  3  .  Y 
1  2  AST  3    1  . Y  
2  1  AST   3   1  Y  .  
2  2  AST   2   1 .  Y 
;
run;

proc sql;
create table want as
select *,
case when max(pstbsfl='Y' and testcd='ALT' and result&amp;gt;=4*baseresult) then 'Y'
     when max(pstbsfl='Y' and testcd='ALT' and result&amp;gt;=4*baseresult)=0 then ' '
  when max(pstbsfl='Y' and testcd='ALT' and result&amp;lt;baseresult)=0 then 'N'
else 'X' end as critfl
 from have
  group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Feb 2023 11:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860419#M339903</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-02-23T11:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860659#M339984</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;thanks for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is what i want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data want;&lt;/P&gt;&lt;P&gt;input $id visitn $test result baseresult $basefl $postbasefl $critfl;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 1&amp;nbsp; ALT&amp;nbsp; 12&amp;nbsp; 3&amp;nbsp; . Y&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 2&amp;nbsp; AST&amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; .Y&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 1&amp;nbsp; AST&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp;1&amp;nbsp; Y .&amp;nbsp; .&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2&amp;nbsp; AST&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp;1 . Y .&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LOGIC:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1.FOR CRITfl eq "Y"-THE RECORDS FOR ID HAVE BOTH ALT AND AST TESTS AND THE CRITFL SHOULD BE FLAGGED "Y" FOR ALL THOSE RECORDS OF THE ID IF THE ID HAS ATLEAST ONE RECORD WITH POSTBASEFL AS "Y" AND RESULT&amp;gt;=4*BASERESULT.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;2. FOR CRITFL EQ "N" -FOR ID 1 IT SHOULD BE FLAGGED "N" if there is no record at all where postbasefl eq "Y"&amp;nbsp; and result&amp;gt;=4*baseresult..&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;3.FOR CRITFL eq ""- IF THE ID DOESNT HAVE ANY POSTBASEFL EQ "Y" RECORD FOR THE TEST ALT THEN THE ID SHOULD HAVE CRITFL "".&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;HERE IS THE FLOWCHART IN CASE IF THE LOGIC IS STILL NOT CLEAR&lt;/STRONG&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="sandhya88_0-1677244081125.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80811i1A362C1B5A74F853/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sandhya88_0-1677244081125.png" alt="sandhya88_0-1677244081125.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Your Response is much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TIA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 13:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860659#M339984</guid>
      <dc:creator>sandhya88</dc:creator>
      <dc:date>2023-02-24T13:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860829#M340046</link>
      <description>&lt;P&gt;I think your LOGIC doesn't match your FLOWCHART.&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;FOR ID HAVE BOTH ALT AND AST TESTS&amp;nbsp;"&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;but it didn't appear in your FLOWCHART.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Anyway,try this one :&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 Input Id visitn testcd $ result baseresult basefl $  pstbsfl $;
 datalines;
1  1  ALT  12  3  .  Y 
1  2  AST  3    1  . Y  
2  1  AST   3   1  Y  .  
2  2  AST   2   1 .  Y 
;
run;

proc sql;
create table want as
select *,
case when max(pstbsfl='Y' and testcd='ALT' and result&amp;gt;=4*baseresult) then 'Y'
     when max(pstbsfl='Y' and testcd='ALT' and result&amp;lt;4*baseresult) then 'N'
     when max(pstbsfl='Y' and testcd='ALT' and result&amp;gt;=4*baseresult)=0 then ' '
else 'X' end as critfl
 from have
  group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Feb 2023 11:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/860829#M340046</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-02-25T11:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/861332#M340246</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; thanks for your response and definitely its not populating Y,N OR NULL&lt;BR /&gt;Values of an ID If the test is other than ALT.&lt;BR /&gt;SO HERE MY AIM IS TO POPULATE THE CRITFL WITH 'Y' FOR ALL(BOTH ALT,AST) THE RECORDS OF THE ID IF ATLEAST ONE RECORD IS HAVING ALT PSTBSFL AND ITS RESULT&amp;gt;=4*BASERESULT AND NULL FOR CRITFL IF THE ID DOESNT HAVE ANY RECORD WITH ALT AND CRITFL AS "N" IF THE ID HAS A ALT POSTBSFL RECORD BUT THE RESULT^&amp;gt;=4*BASERESULT.</description>
      <pubDate>Tue, 28 Feb 2023 11:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/861332#M340246</guid>
      <dc:creator>sandhya88</dc:creator>
      <dc:date>2023-02-28T11:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/861345#M340250</link>
      <description>&lt;PRE&gt;/*
If you think there are something wrong in my code,
I think you'd better post an example to illustrate,
It is hard to understand what is your mean by literally.
Anyway, Try this code. If the result is not right,POST AN EXAMPLE.
*/
data have;
 Input Id visitn testcd $ result baseresult basefl $  pstbsfl $;
 datalines;
1  1  ALT  12  3  .  Y 
1  2  AST  3    1  . Y  
2  1  AST   3   1  Y  .  
2  2  AST   2   1 .  Y 
;
run;

proc sql;
create table want as
select *,
case when max(pstbsfl='Y' and testcd='ALT' and result&amp;gt;=4*baseresult) then 'Y'
     when max(pstbsfl='Y' and testcd='ALT' and result&amp;lt;4*baseresult) then 'N'
     when max(testcd='ALT')=0 then ' '
else 'X' end as critfl
 from have
  group by id;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Feb 2023 12:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/861345#M340250</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-02-28T12:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/861362#M340256</link>
      <description>&lt;P&gt;&lt;U&gt;ok this is how i want the data to be finally if that helps:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sandhya88_0-1677589544920.png" style="width: 786px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80929i18A11E388FAB8843/image-dimensions/786x451?v=v2" width="786" height="451" role="button" title="sandhya88_0-1677589544920.png" alt="sandhya88_0-1677589544920.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;YELLOW HIGHLIGHTED: &lt;EM&gt;CRITFL-Y&lt;/EM&gt;&lt;/STRONG&gt; FOR ALL THE RECORDS OF THE ID AS THE ID 004 HAS ATLEAST ONE ALT PSTBSFL RECORD WITH RESULT&amp;gt;=4*BASERSLT&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;GREEN HIGHLIGHTED: &lt;EM&gt;CRITFL-N&lt;/EM&gt;&lt;/STRONG&gt; FOR ALL THE RECORDS OF ID 005 AS THERE IS NO PSTBSFL ALT RECORD WITH RESULT&amp;gt;=4*BASERSLT&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PEACH HIGHLIGHTED: &lt;EM&gt;CRITFL-.&lt;/EM&gt;&lt;/STRONG&gt; FOR ALL THE RECORDS OF THE ID 006 AS THERE ARE NO PSTBSFL ALT RECORDS AT ALL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 13:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/861362#M340256</guid>
      <dc:creator>sandhya88</dc:creator>
      <dc:date>2023-02-28T13:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging all the records within a id if atleast one record meets the predefined criterion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/861738#M340377</link>
      <description>&lt;PRE&gt;/*
OK. Test the following code.
If there was something wrong,post an example.
*/
data have;
 Input Id visitn testcd $ result baseresult basefl $  pstbsfl $;
 datalines;
1  1  ALT  12  3  .  Y 
1  2  AST  3    1  . Y  
2  1  AST   3   1  Y  .  
2  2  AST   2   1 .  Y 
;
run;

proc sql;
create table want as
select *,
case when max(pstbsfl='Y' and testcd='ALT') and 
          max(pstbsfl='Y' and testcd='ALT' and result&amp;gt;=4*baseresult) then 'Y'
     when max(pstbsfl='Y' and testcd='ALT') and 
          max(pstbsfl='Y' and testcd='ALT' and result&amp;gt;=4*baseresult)=0 then 'N'
     when max(pstbsfl='Y' and testcd='ALT')=0 then ' '
else 'X' end as critfl
 from have
  group by id;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDITED.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 14:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-all-the-records-within-a-id-if-atleast-one-record-meets/m-p/861738#M340377</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-03-01T14:45:18Z</dc:date>
    </item>
  </channel>
</rss>

