<?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: Changing multiple gender observations to fit a unique patient identifier in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273342#M7636</link>
    <description>&lt;P&gt;To implement the policy : keep consistent gender assignment:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Patient_ID    Gender $;
datalines;
104                 M
104                 U
104                 M
212                 F
212                 F
212                 U
212                 F
1102              M
1102               . 
999 M
999 F
999 .
999 U
;

proc sql;
create table gender as
select 
	patient_id, 
	case
		when count(distinct Gender) = 1 then max(Gender)
		else ""
		end as gender
from have
where Gender in ("M", "F")
group by patient_id;
select * from gender;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 26 May 2016 18:04:33 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-05-26T18:04:33Z</dc:date>
    <item>
      <title>Changing gender to match patient ID number</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273321#M7628</link>
      <description>&lt;P&gt;I am looking for a solution to my current problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;SAS 9.4&lt;/P&gt;&lt;P&gt;I have a variable with patient IDs and another variable of gender. The patient IDs are entered multiple times but the corresponding genders are not always entered or are "unidentified" (U). I would like to find a way to change all the genders to the same if they fall under the same patient ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Patient ID &amp;nbsp; &amp;nbsp;Gender&lt;/P&gt;&lt;P&gt;104 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;/P&gt;&lt;P&gt;104 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; U&lt;/P&gt;&lt;P&gt;104 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;/P&gt;&lt;P&gt;212 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;212 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;212 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; U&lt;/P&gt;&lt;P&gt;212 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;1102 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;/P&gt;&lt;P&gt;1102 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 17:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273321#M7628</guid>
      <dc:creator>mphqueens</dc:creator>
      <dc:date>2016-05-26T17:05:08Z</dc:date>
    </item>
    <item>
      <title>Changing multiple gender observations to fit a unique patient identifier</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273319#M7635</link>
      <description>&lt;P&gt;I am looking for a solution to my current problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;SAS 9.4&lt;/P&gt;&lt;P&gt;I have a variable with patient IDs and another variable of gender. The patient IDs are entered multiple times but the corresponding genders are not always entered or are "unidentified" (U). I would like to find a way to change all the genders to the same if they fall under the same patient ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Patient ID &amp;nbsp; &amp;nbsp;Gender&lt;/P&gt;&lt;P&gt;104 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;/P&gt;&lt;P&gt;104 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; U&lt;/P&gt;&lt;P&gt;104 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;/P&gt;&lt;P&gt;212 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;212 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;212 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; U&lt;/P&gt;&lt;P&gt;212 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;1102 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;/P&gt;&lt;P&gt;1102 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 17:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273319#M7635</guid>
      <dc:creator>mphqueens</dc:creator>
      <dc:date>2016-05-26T17:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gender to match patient ID number</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273327#M7630</link>
      <description>&lt;P&gt;Do you have any that look like this ?&lt;/P&gt;
&lt;P&gt;104 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;/P&gt;
&lt;P&gt;104 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; U&lt;/P&gt;
&lt;P&gt;104&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; F&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so what rule would you like for selecting between M and F?&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 17:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273327#M7630</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-26T17:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gender to match patient ID number</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273328#M7631</link>
      <description>&lt;P&gt;These days, it's possible that all three values were valid at the time they were recorded.&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 17:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273328#M7631</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-26T17:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gender to match patient ID number</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273330#M7632</link>
      <description>&lt;P&gt;Not that I have found! It seems that they are consistent with either M or F with some U and blanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 17:33:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273330#M7632</guid>
      <dc:creator>mphqueens</dc:creator>
      <dc:date>2016-05-26T17:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gender to match patient ID number</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273331#M7633</link>
      <description>&lt;P&gt;However, if I found any with M and F and U, I would assume the first recorded gender would be the correct one.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 17:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273331#M7633</guid>
      <dc:creator>mphqueens</dc:creator>
      <dc:date>2016-05-26T17:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Changing multiple gender observations to fit a unique patient identifier</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273342#M7636</link>
      <description>&lt;P&gt;To implement the policy : keep consistent gender assignment:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Patient_ID    Gender $;
datalines;
104                 M
104                 U
104                 M
212                 F
212                 F
212                 U
212                 F
1102              M
1102               . 
999 M
999 F
999 .
999 U
;

proc sql;
create table gender as
select 
	patient_id, 
	case
		when count(distinct Gender) = 1 then max(Gender)
		else ""
		end as gender
from have
where Gender in ("M", "F")
group by patient_id;
select * from gender;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 May 2016 18:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273342#M7636</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-05-26T18:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Changing multiple gender observations to fit a unique patient identifier</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273343#M7637</link>
      <description>&lt;P&gt;Here's a quick SQL query that will set all to the M/F observed assuming only one value is observed. If you have both a M/F&amp;nbsp;for a single patient_id then that will break this code. You'll need to determine how to handle those cases if they occur in your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Patient_ID $   Gender $;
cards;
104                 M
104                 U
104                 M
212                 F
212                 F
212                 U
212                 F
1102                M
1102               
;
run; 

proc sql;
create table want as
select a.patient_id, b.gender
from have as a
left join (select distinct patient_id, gender from have where not missing(gender) and gender ne "U") as b
on a.patient_id=b.patient_id
order by 1, 2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 May 2016 18:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273343#M7637</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-26T18:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gender to match patient ID number</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273349#M7639</link>
      <description>&lt;P&gt;If you're more comfortable with a DATA step approach, here's how it could be done:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;length first_gender $ 1;&lt;/P&gt;
&lt;P&gt;do until (last.patient_id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by patient_id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if first_gender=' ' and gender in ('F', 'M') then first_gender = gender;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if first_gender=' ' then first_gender=gender;&lt;/P&gt;
&lt;P&gt;do until (last.patient_id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by patient_id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; gender = first_gender;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop first_gender;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 18:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273349#M7639</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-26T18:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Changing multiple gender observations to fit a unique patient identifier</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273363#M7640</link>
      <description>&lt;P&gt;This worked perfectly...thank you! Is there a way to merge this table back to my original data set?&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 19:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273363#M7640</guid>
      <dc:creator>mphqueens</dc:creator>
      <dc:date>2016-05-26T19:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gender to match patient ID number</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273368#M7641</link>
      <description>&lt;P&gt;Do you have a date that goes along with the data? How can you identify which is the first/last besides order which isn't a good way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given the world today, it may be more appropriate to use the last gender, rather than first.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 19:23:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273368#M7641</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-26T19:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gender to match patient ID number</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273373#M7642</link>
      <description>Yes, the data is ordered by date.&lt;BR /&gt;</description>
      <pubDate>Thu, 26 May 2016 19:29:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273373#M7642</guid>
      <dc:creator>mphqueens</dc:creator>
      <dc:date>2016-05-26T19:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gender to match patient ID number</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273474#M7654</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Patient_ID $   Gender $;
cards;
104                 M
104                 U
104                 M
212                 F
212                 F
212                 U
212                 F
1102                M
1102               
;
run; 
proc sort data=have(keep=Patient_ID Gender where=(Gender in ('F' 'M'))) out=temp nodupkey;
by Patient_ID Gender ;
run;
proc sort data=have;by Patient_ID ;run;
data want;
 merge have(drop=Gender) temp;
 by Patient_ID ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 May 2016 03:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Changing-gender-to-match-patient-ID-number/m-p/273474#M7654</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-27T03:24:11Z</dc:date>
    </item>
  </channel>
</rss>

