<?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 Flagging records based on a criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577540#M163651</link>
    <description>&lt;P&gt;Good Afternoon everyone. Thanks in advance.&amp;nbsp; So, I have a dataset with many variables, including one for DND(do not display) flag. This dataset is created after running a macro which was not originally created by me. I have to modify this macro to include another rule so that when that happens, DND is 'Y' rather than current 'N'. The rule is that when for a certain product type, there is a provider and a specific treatment category and entity type, and the same provider within the same product type has the same treatment category but a different entity type, a specific entity type should be preferred and the other record should have DND as 'Y'. The following data should clear this up. For simplicity, I have only included variables which are of interest, actual dataset has 15-16 other variables too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;

input product $ provider_no $ TC $ ENTITY_TYPE $ DND $;

DATALINES;

&amp;nbsp;MAB1 ABC001 MRI TYPE=1 N

&amp;nbsp;MAB1 ABC001 MRI TYPE =2 N

MAB1&amp;nbsp; BCD002 FLU TYPE=1 N

MAB1&amp;nbsp; BCD002 TEST TYPE=2 N

;

RUN;



DATA WANT;

input product $ provider_no $ TC $ ENTITY_TYPE $ DND $;

DATALINES;

&amp;nbsp;MAB1 ABC001 MRI TYPE=1 N

&amp;nbsp;MAB1 ABC001 MRI TYPE =2 Y

MAB1&amp;nbsp; BCD002 FLU TYPE=1 N

MAB1&amp;nbsp; BCD002 TEST TYPE=2 N

;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks so much.&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jul 2019 21:25:28 GMT</pubDate>
    <dc:creator>devsas</dc:creator>
    <dc:date>2019-07-29T21:25:28Z</dc:date>
    <item>
      <title>Flagging records based on a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577540#M163651</link>
      <description>&lt;P&gt;Good Afternoon everyone. Thanks in advance.&amp;nbsp; So, I have a dataset with many variables, including one for DND(do not display) flag. This dataset is created after running a macro which was not originally created by me. I have to modify this macro to include another rule so that when that happens, DND is 'Y' rather than current 'N'. The rule is that when for a certain product type, there is a provider and a specific treatment category and entity type, and the same provider within the same product type has the same treatment category but a different entity type, a specific entity type should be preferred and the other record should have DND as 'Y'. The following data should clear this up. For simplicity, I have only included variables which are of interest, actual dataset has 15-16 other variables too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;

input product $ provider_no $ TC $ ENTITY_TYPE $ DND $;

DATALINES;

&amp;nbsp;MAB1 ABC001 MRI TYPE=1 N

&amp;nbsp;MAB1 ABC001 MRI TYPE =2 N

MAB1&amp;nbsp; BCD002 FLU TYPE=1 N

MAB1&amp;nbsp; BCD002 TEST TYPE=2 N

;

RUN;



DATA WANT;

input product $ provider_no $ TC $ ENTITY_TYPE $ DND $;

DATALINES;

&amp;nbsp;MAB1 ABC001 MRI TYPE=1 N

&amp;nbsp;MAB1 ABC001 MRI TYPE =2 Y

MAB1&amp;nbsp; BCD002 FLU TYPE=1 N

MAB1&amp;nbsp; BCD002 TEST TYPE=2 N

;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks so much.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 21:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577540#M163651</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2019-07-29T21:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging records based on a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577542#M163652</link>
      <description>&lt;P&gt;How do you determine which entity type is "preferred"?&amp;nbsp; The lowest value for TYPE= ?&amp;nbsp; Is it just the first one that comes along in the data, or is there some other rule?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 21:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577542#M163652</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-07-29T21:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging records based on a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577543#M163653</link>
      <description>&lt;P&gt;Thanks. For this particular situation, whenever there is both type=1 and type =2, we should prefer type =1.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 21:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577543#M163653</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2019-07-29T21:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging records based on a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577561#M163660</link>
      <description>&lt;P&gt;Actually DND needs to be changed to 'Y' only for those cases where for the same product type, provider and tc, there are both type 1 and type 2 entity types and type 2 should be changed to Y. Rest everything else remains the same.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 22:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577561#M163660</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2019-07-29T22:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging records based on a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577564#M163662</link>
      <description>&lt;P&gt;Get rid of the extraneous space in TYPE =2.&lt;/P&gt;
&lt;P&gt;Get your code to run correctly in SAS, then paste here, or else paste your posted code back into SAS to make sure it runs correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this give you what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input product $ provider_no $ TC $ ENTITY_TYPE $ DND $;
datalines;
MAB1 ABC001 MRI TYPE=1 N
MAB1 ABC001 MRI TYPE=2 N
MAB1  BCD002 FLU TYPE=1 N
MAB1  BCD002 TEST TYPE=2 N
;
run;

data want;
	set have;
	by product provider_no tc entity_type notsorted;  * remove notsorted if it does not apply ;
	first=first.tc;		* for debugging ;
	if first.tc then ;  * do nothing ;
	else dnd='Y';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 23:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577564#M163662</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-07-29T23:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging records based on a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577577#M163664</link>
      <description>&lt;P&gt;Thanks for the reply. Oh sorry about the mistake in my code, generally I test it before pasting here, but something slipped away this time.&lt;/P&gt;
&lt;P&gt;I cannot test the code at this point, but not sure if this will work in case entity type has different value than either of the ones i mentioned. For instance, if two records have same product type, provider and tc code but entity values are type=1 and type =3, I dont want the DND to change in that case. In other words, only when there are two records for same, product, provider and TC code and entity types are type =1 and type =2, i want to display record with type=2 as Y for DND. Rest for everything else, DND remains the same as original.&lt;/P&gt;
&lt;P&gt;Also, I hope the code wont change if there are additional variables, such as counts, avg_cost etc?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 01:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577577#M163664</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2019-07-30T01:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging records based on a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577592#M163672</link>
      <description>&lt;P&gt;Sorry, in the future please state your requirements clearly and in their entirety.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either run with what I provided and code your own solution, or perhaps someone else will spoon feed you a solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unsubscribing...&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 04:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577592#M163672</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-07-30T04:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging records based on a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577857#M163784</link>
      <description>&lt;P&gt;The following code gets it halfway- meaning it does change to Y for those cases where there are both type=1 and type=2, but it also changes DND to Y when there is only type=2 only and I dont want it to change.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data want2;
   set have;
      by BL_BCBS_PROD_CD bl_pln_prvdr_num tc_code tc_desc;  
 if LAST.tc_code and entity_type = 'TYPE=2' then dont_disp_ind='Y' ; 
    else dont_disp_ind=dont_disp_ind;
 run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I tried another code and though I dont any issue with it, it still doesnt solve the problem. Infact it doesnt do even what above code did. Not sure what im missing here.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want4;
	set have;
	by BL_BCBS_PROD_CD bl_pln_prvdr_num tc_code tc_desc;  
	IF FIRST.TC_CODE THEN N=0;N= N+1;
	IF N=2 AND ENTITY_TYPE = 'TYPE=2' then dont_disp_ind='Y';
	else dont_disp_ind=dont_disp_ind;
    run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jul 2019 18:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577857#M163784</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2019-07-30T18:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging records based on a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577892#M163805</link>
      <description>&lt;P&gt;Just in case anyone is interested- i found the solution and it tests fine.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want5;
   set have;
      by BL_BCBS_PROD_CD bl_pln_prvdr_num tc_code tc_desc;  
 
    if first.tc_code and last.tc_code then dont_disp_ind=dont_disp_ind;
	else if LAST.tc_code and entity_type = 'TYPE=2' then dont_disp_ind='Y' ; 
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jul 2019 20:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-records-based-on-a-criteria/m-p/577892#M163805</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2019-07-30T20:26:36Z</dc:date>
    </item>
  </channel>
</rss>

