<?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: Labeling patients based on selection criteria? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Labeling-patients-based-on-selection-criteria/m-p/635455#M78066</link>
    <description>&lt;P&gt;Your example data is missing at least one of your values, so we can't actual test to see what it looks like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because of the structure of your "hierarchy" I would strongly suggest testing for medicaid and medicare first, then medicare of that, Then the private, then voucher and leave cash as the default if none are found.&lt;/P&gt;
&lt;P&gt;If there are any other payment possibilities you need to say so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input PatientID	Payment $;
datalines;
1	Cash
1	Cash
1	Cash
1	Cash
2	Cash
2	Medicare
2	Medicaid
2	Medicaid
3	Cash
3	Private
3	Cash
3	Private
;
proc sort data=have;
   by patientid;
run;
proc transpose data=have
   out=trans (drop=_name_)
;
by patientid;
var payment;
run;

data want;
	set trans;
	array c col: ;
	if index(catx(',',of c(*)),'Medicaid') then Payment='Medicaid';
	else if index(catx(',',of c(*)),'Medicare') then Payment='Medicare';
	else if index(catx(',',of c(*)),'Private') then Payment='Private';
	else if index(catx(',',of c(*)),'Coupon') then Payment='Coupon';
	else Payment='Cash';
run;
&lt;/PRE&gt;
&lt;P&gt;after the logic is working you would add : Drop col: ; to get rid of all the individual values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: if your spelling is not the same EVERY SINGLE TIME for Medicaid, Medicare etc. then you should fix that before starting this. Otherwise your comparisons may get very complicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The INDEX function will return a positive value that SAS treats as true for the IF when the word is found. The CATX function combines all of the payments recorded into one long string to search. The array uses the list COL: to group all of the columns by the default variable name that Proc Transpose creates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you expect other variables to be included say so now and provide examples.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Mar 2020 22:19:42 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-03-27T22:19:42Z</dc:date>
    <item>
      <title>Labeling patients based on selection criteria?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Labeling-patients-based-on-selection-criteria/m-p/635451#M78062</link>
      <description>&lt;P&gt;This has been stumping for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an Rx data set that are observations of medication dispensings. I need to label each patient based on the hierarchical criteria in the flow chart attached.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Patient ID&lt;/TD&gt;&lt;TD&gt;Payment&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Cash&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Cash&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Cash&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Cash&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Cash&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Medicare&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Medicaid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Medicaid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Cash&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Private&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Cash&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Private&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want (based on the attached in the flow chart):&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Patient ID&lt;/TD&gt;&lt;TD&gt;Payment&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Cash&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Medicaid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Private&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 27 Mar 2020 21:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Labeling-patients-based-on-selection-criteria/m-p/635451#M78062</guid>
      <dc:creator>cmccor</dc:creator>
      <dc:date>2020-03-27T21:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Labeling patients based on selection criteria?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Labeling-patients-based-on-selection-criteria/m-p/635455#M78066</link>
      <description>&lt;P&gt;Your example data is missing at least one of your values, so we can't actual test to see what it looks like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because of the structure of your "hierarchy" I would strongly suggest testing for medicaid and medicare first, then medicare of that, Then the private, then voucher and leave cash as the default if none are found.&lt;/P&gt;
&lt;P&gt;If there are any other payment possibilities you need to say so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input PatientID	Payment $;
datalines;
1	Cash
1	Cash
1	Cash
1	Cash
2	Cash
2	Medicare
2	Medicaid
2	Medicaid
3	Cash
3	Private
3	Cash
3	Private
;
proc sort data=have;
   by patientid;
run;
proc transpose data=have
   out=trans (drop=_name_)
;
by patientid;
var payment;
run;

data want;
	set trans;
	array c col: ;
	if index(catx(',',of c(*)),'Medicaid') then Payment='Medicaid';
	else if index(catx(',',of c(*)),'Medicare') then Payment='Medicare';
	else if index(catx(',',of c(*)),'Private') then Payment='Private';
	else if index(catx(',',of c(*)),'Coupon') then Payment='Coupon';
	else Payment='Cash';
run;
&lt;/PRE&gt;
&lt;P&gt;after the logic is working you would add : Drop col: ; to get rid of all the individual values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: if your spelling is not the same EVERY SINGLE TIME for Medicaid, Medicare etc. then you should fix that before starting this. Otherwise your comparisons may get very complicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The INDEX function will return a positive value that SAS treats as true for the IF when the word is found. The CATX function combines all of the payments recorded into one long string to search. The array uses the list COL: to group all of the columns by the default variable name that Proc Transpose creates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you expect other variables to be included say so now and provide examples.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 22:19:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Labeling-patients-based-on-selection-criteria/m-p/635455#M78066</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-27T22:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Labeling patients based on selection criteria?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Labeling-patients-based-on-selection-criteria/m-p/635491#M78067</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input PatientID	Payment $;
datalines;
1	Cash
1	Cash
1	Cash
1	Cash
2	Cash
2	Medicaid
2	Medicaid
2	Medicaid
3	Cash
3	Private
3	Cash
3	Private
;
data want;
if _n_=1 then do;
 if 0 then set have;
 declare hash h();
 h.definekey('Payment');
 h.definedone();
end;
 set have;
 if h.check() ne 0 then output;
 h.ref();
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Mar 2020 11:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Labeling-patients-based-on-selection-criteria/m-p/635491#M78067</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-28T11:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Labeling patients based on selection criteria?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Labeling-patients-based-on-selection-criteria/m-p/635562#M78078</link>
      <description>This worked. Thank you!</description>
      <pubDate>Sat, 28 Mar 2020 23:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Labeling-patients-based-on-selection-criteria/m-p/635562#M78078</guid>
      <dc:creator>cmccor</dc:creator>
      <dc:date>2020-03-28T23:15:44Z</dc:date>
    </item>
  </channel>
</rss>

