<?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: Filling missing character variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776512#M246981</link>
    <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;&lt;P&gt;The code did not work.&amp;nbsp; Here is the output.&amp;nbsp; Still the sex is missing from row. The log did not indicate any errors though. Am i doing something wrong?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jagscbe_0-1635258578858.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65055i980A5367A706ED49/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jagscbe_0-1635258578858.png" alt="jagscbe_0-1635258578858.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Oct 2021 14:31:41 GMT</pubDate>
    <dc:creator>Bluejags</dc:creator>
    <dc:date>2021-10-26T14:31:41Z</dc:date>
    <item>
      <title>Filling missing character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776280#M246842</link>
      <description>&lt;P&gt;I have a data that looks lie this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pat_ID City Sex&amp;nbsp;&lt;/P&gt;&lt;P&gt;012&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;012&amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;/P&gt;&lt;P&gt;012 1&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;015&amp;nbsp; 2&amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;015 2&lt;/P&gt;&lt;P&gt;016 1&amp;nbsp; &amp;nbsp; M&lt;/P&gt;&lt;P&gt;016 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to fill in the gender in the last column using the info available.&amp;nbsp; I am new and would appreciate any help.&amp;nbsp; The RETAIN statement works for PAT_ID 015 and 016 but not for the 012, as the sex info is missing in the first row.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 19:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776280#M246842</guid>
      <dc:creator>Bluejags</dc:creator>
      <dc:date>2021-10-25T19:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776283#M246844</link>
      <description>&lt;P&gt;SQL is easiest here, as it allows for summary and row level calculations in a single code block - it still does the extra steps behind the scenes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select pat_id, city, coalesce(sex, max(sex)) as sex
from have
group by pat_id
order by 1, 2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise something like this may work as well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data gender;
set have;
where not missing(sex);
by pat_id;
if first.pat_id;
run;

data want;
merge have gender (rename=sex = sex_found);
by pat_id;
sex = coalescec(sex, sex_found);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404284"&gt;@Bluejags&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a data that looks lie this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pat_ID City Sex&amp;nbsp;&lt;/P&gt;
&lt;P&gt;012&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;012&amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;/P&gt;
&lt;P&gt;012 1&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;015&amp;nbsp; 2&amp;nbsp; &amp;nbsp; F&lt;/P&gt;
&lt;P&gt;015 2&lt;/P&gt;
&lt;P&gt;016 1&amp;nbsp; &amp;nbsp; M&lt;/P&gt;
&lt;P&gt;016 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to fill in the gender in the last column using the info available.&amp;nbsp; I am new and would appreciate any help.&amp;nbsp; The RETAIN statement works for PAT_ID 015 and 016 but not for the 012, as the sex info is missing in the first row.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 19:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776283#M246844</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-25T19:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776443#M246951</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Pat_ID City Sex $;
cards;
012   1      
012  1     M
012 1     
015  2    F
015 2
016 1    M
016 1
;

data want;
 merge have have(where=(new_sex is not missing) rename=(sex=new_sex));
 by Pat_ID City;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Oct 2021 12:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776443#M246951</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-10-26T12:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776512#M246981</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;&lt;P&gt;The code did not work.&amp;nbsp; Here is the output.&amp;nbsp; Still the sex is missing from row. The log did not indicate any errors though. Am i doing something wrong?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jagscbe_0-1635258578858.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65055i980A5367A706ED49/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jagscbe_0-1635258578858.png" alt="jagscbe_0-1635258578858.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 14:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776512#M246981</guid>
      <dc:creator>Bluejags</dc:creator>
      <dc:date>2021-10-26T14:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776516#M246984</link>
      <description>&lt;P&gt;Hi Reeza, the codes didnt work.&amp;nbsp; Still getting blank cells for gender.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 14:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776516#M246984</guid>
      <dc:creator>Bluejags</dc:creator>
      <dc:date>2021-10-26T14:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776528#M246989</link>
      <description>&lt;P&gt;That's a screenshot of your HAVE data set not the newly created data set, WANT. Check your output again please.&lt;/P&gt;
&lt;P&gt;EDIT: I just tested all three solutions posted (2 of mine and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;) all work as expected on the posted sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 15:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776528#M246989</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-26T15:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776532#M246991</link>
      <description>&lt;P&gt;MY BAD. Thanks Reeza for pointing out that i was not looking into the WANT and only the HAVE.&amp;nbsp; I am new to SAS&amp;nbsp; and didn't realize the output screen has option to click to look into all files generated for the set of codes.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also thanks to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;too.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 15:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-character-variable/m-p/776532#M246991</guid>
      <dc:creator>Bluejags</dc:creator>
      <dc:date>2021-10-26T15:50:43Z</dc:date>
    </item>
  </channel>
</rss>

