<?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: Adding data into missing cells in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Adding-data-into-missing-cells/m-p/545996#M8135</link>
    <description>&lt;P&gt;Another version of it would be the following. The data does not have to have an age or a gender in the first row for each individual. NB! It does not work if the age is calculated by the day itself. So, if a person is 21 day one and 22 day two, this solution will give you 22 for all rows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table run2 as 
	select ID, Day, age2, distance, gender2
		from run as r1 left join (select id as id1, max(Age) as Age2, max(gender) as Gender2 from run r2 group by id)
		on r1.id = r2.id
	order by id, day;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 25 Mar 2019 23:49:21 GMT</pubDate>
    <dc:creator>heffo</dc:creator>
    <dc:date>2019-03-25T23:49:21Z</dc:date>
    <item>
      <title>Adding data into missing cells</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-data-into-missing-cells/m-p/545990#M8133</link>
      <description>&lt;P&gt;Hellow SAS community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After merging several data sets I have a data set like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; day&amp;nbsp; &amp;nbsp;age&amp;nbsp; distance&amp;nbsp; gender&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;43&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;43&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;43&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;24&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F&amp;nbsp;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;24&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;24&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;24&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;18&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;36&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M&amp;nbsp;&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;36&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;36&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&amp;nbsp;&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;36&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&amp;nbsp;&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;36&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically the day a person doesn't run, I create a new observation with Distance = 0. However, my merge ended up that I have lots of missing data in all of the rest variables except&amp;nbsp;id and day. How could I add data back to the missing cell where we can infer information from other cells: for example, id 1 is Female (F) by looking at day 1, 4, 5, so day 2, 3 we know that the person with id 1 is Female (F).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please share what you think can help me solve this issue&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 23:02:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-data-into-missing-cells/m-p/545990#M8133</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2019-03-25T23:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding data into missing cells</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-data-into-missing-cells/m-p/545994#M8134</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data have;
input id  day   age  distance  gender $;
datalines;
1    1       21      2           F
1    2        .        0           . 
1    3        .        0           .
1    4       21      5           F
1    5       21      1           F
2    1       43      2           M
2    2       43      2           M
2    3        .        0            .
2    4       43      3           M
2    5        .       0             .
3    1       24      5           F 
3    2       24      5           F
3    3       24      5           F
3    4       24      5           F
3    5        .        0           . 
4    1       18      2          M
4    2        .        0           .
4    3        .        0           .
4    4        .        0           .
4    5        .        0           .
5   1       36       10        M 
5   2       36        8         M
5   3       36        8         M 
5   4       36        9         M 
5   5       36        7         M  
;
run;

data want;
   set have;
   by id;
   length r_gender $ 1.;
   retain r_age r_gender;
   if first.id then do;
      r_gender=gender;
   end;
   if not missing(age) then r_age=age;
   if missing (age) then age=r_age;
   if missing (gender) then gender=r_gender;
   drop r_age r_gender;
run;&lt;/PRE&gt;
&lt;P&gt;Please note the data provided in the form of a data step and pasted into a code box opened with the forum's {I} icon. The data step so code can be tested and the code box to preserve formatting of code or log entries. The main message windows on this forum will reformat text, often making code not run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The BY id allows use of the First. logic to identify the first record for each id. Assumes that gender will be present and not change during the course of the data.&lt;/P&gt;
&lt;P&gt;Since Age might change during the course of your data check to see if the incoming record has an age value and don't assume that all records will be for the same value.&lt;/P&gt;
&lt;P&gt;The Retain statement creates variables whose values will be kept for the following records. So they are available to assign when missing.&lt;/P&gt;
&lt;P&gt;Check for missing and assign the value of the retained variable when they are.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 23:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-data-into-missing-cells/m-p/545994#M8134</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-25T23:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Adding data into missing cells</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-data-into-missing-cells/m-p/545996#M8135</link>
      <description>&lt;P&gt;Another version of it would be the following. The data does not have to have an age or a gender in the first row for each individual. NB! It does not work if the age is calculated by the day itself. So, if a person is 21 day one and 22 day two, this solution will give you 22 for all rows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table run2 as 
	select ID, Day, age2, distance, gender2
		from run as r1 left join (select id as id1, max(Age) as Age2, max(gender) as Gender2 from run r2 group by id)
		on r1.id = r2.id
	order by id, day;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Mar 2019 23:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-data-into-missing-cells/m-p/545996#M8135</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-03-25T23:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Adding data into missing cells</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-data-into-missing-cells/m-p/545997#M8136</link>
      <description>&lt;P&gt;I would probably change the if statements for coalesce(c). Just less code and a bit easier to read IMHO.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	age = coalesce(age,r_age);
	gender = coalescec(gender, r_gender);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Mar 2019 23:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-data-into-missing-cells/m-p/545997#M8136</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-03-25T23:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Adding data into missing cells</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-data-into-missing-cells/m-p/545998#M8137</link>
      <description>&lt;P&gt;If you do this the easy way, you don't even need to know the variable names.&amp;nbsp; You just need data that is in sorted order by ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;update have (obs=0) have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 00:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-data-into-missing-cells/m-p/545998#M8137</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-26T00:26:31Z</dc:date>
    </item>
  </channel>
</rss>

