<?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: How do I retain value in missing observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731235#M227784</link>
    <description>&lt;P&gt;So you have now given us some more information - namely about the position of SEQ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have NOT stated why collapsed and count are propagated from obs 4 through 5 and 6, but obs 7 is not propagated.&amp;nbsp;Is it because ex='Y' in obs 4, but not in obs 7?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When does propagation stop?&amp;nbsp; In the above case, obs 7 has data that stops propagation of data from obs 4, but what if there were no such data after obs 4?&amp;nbsp; When would propagation stop, if at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you show only only one subjid in your data.&amp;nbsp; You didn't say whether data should be propagated across subjects (probably not, but it would be good to have it stated).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In short, help us help you - by providing a sufficient description of the problem such that you won't have to answer lots of follow-up questions.&amp;nbsp; That's probably a more valuable skill to develop than sas coding, even in this forum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 04 Apr 2021 14:20:31 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-04-04T14:20:31Z</dc:date>
    <item>
      <title>How do I retain value in missing observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731180#M227765</link>
      <description>Hi,&lt;BR /&gt;I can’t get my head around to fix this piece of code, my data looks somewhat like this with 4 variable &lt;BR /&gt;Data have;&lt;BR /&gt;Subjid collapse  count  seq&lt;BR /&gt;101               1&lt;BR /&gt;101  1     1    2&lt;BR /&gt;101  1     1    3&lt;BR /&gt;101               4&lt;BR /&gt;101               5&lt;BR /&gt;101   1     1   6&lt;BR /&gt;101               7&lt;BR /&gt;&lt;BR /&gt;I want to retain the variable collapse and count at missing seq 4 &amp;amp;5.&lt;BR /&gt;For e.g I want my dataset to look like:&lt;BR /&gt;&lt;BR /&gt;Data have;&lt;BR /&gt;Subjid collapse  count  seq&lt;BR /&gt;101               1&lt;BR /&gt;101  1     1    2&lt;BR /&gt;101  1     1    3&lt;BR /&gt;101   1     1   4&lt;BR /&gt;101   1     1   5&lt;BR /&gt;101   1     1   6&lt;BR /&gt;101               7&lt;BR /&gt;&lt;BR /&gt;Please let me know how I can fix this, I cannot use the seq variable to code because the situation can be different for different subjids.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance &lt;BR /&gt;</description>
      <pubDate>Sat, 03 Apr 2021 23:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731180#M227765</guid>
      <dc:creator>nans_p</dc:creator>
      <dc:date>2021-04-03T23:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I retain value in missing observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731181#M227766</link>
      <description>&lt;P&gt;Please explain the required logic a bit more in detail - especially why seq remains missing for the first and last obs in your sample data.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 23:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731181#M227766</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-03T23:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I retain value in missing observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731184#M227768</link>
      <description>&lt;P&gt;I think you need to make a working data step to show the initial condition of your data.&amp;nbsp; It appears that SEQ is missing for obs 1 and 7.&amp;nbsp; Instead you have collapse=1 for the first obs and collapse=7 for the last.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it that is not your intention, then you should show missing values for collapse and count&amp;nbsp; (two .'s&amp;nbsp; between subjid and seq).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I am correct (this is untested until in absence of actual startup data in a data step), then this code should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  set have;
  retain _last_collapse _last_count;

  if collapse^=. then _last_collapse=collapse;
  if count^=.    then _last_count=count;

  if collapse=.  then collapse=_last_collapse;
  if count=.     then count=_last_count;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Apr 2021 03:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731184#M227768</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-04T03:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I retain value in missing observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731207#M227776</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for not being so specific - below is a clear explanation. Data Have is how my dataset looks like and Data want is how I want my data too look like.&lt;/P&gt;
&lt;P&gt;Because I have collapsed a record highlighted in green, I want to flag all the associated date records which fall from the 02-Dec-17 to 16-Jan-18. My question is how do I retain the collapsed and the count variable at observation 5&amp;amp;6 of the seq variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NanitaPatel_1-1617523406475.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56892i224B3C3666FCECA7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NanitaPatel_1-1617523406475.png" alt="NanitaPatel_1-1617523406475.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Apr 2021 08:07:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731207#M227776</guid>
      <dc:creator>nans_p</dc:creator>
      <dc:date>2021-04-04T08:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I retain value in missing observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731218#M227782</link>
      <description>&lt;P&gt;So you simply want to carry forward the last non-missing observation?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by subjid;
retain _coll _cnt;
if first.subjid
then do;
  _coll = .;
  _cnt = .;
end;
if collapsed ne .
then _coll = collapsed;
else collapsed = _coll;
if count ne .
then _cnt = count;
else count = _cnt;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, for lack of&amp;nbsp;&lt;EM&gt;usable&lt;/EM&gt; example data.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Apr 2021 11:14:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731218#M227782</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-04T11:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I retain value in missing observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731235#M227784</link>
      <description>&lt;P&gt;So you have now given us some more information - namely about the position of SEQ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have NOT stated why collapsed and count are propagated from obs 4 through 5 and 6, but obs 7 is not propagated.&amp;nbsp;Is it because ex='Y' in obs 4, but not in obs 7?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When does propagation stop?&amp;nbsp; In the above case, obs 7 has data that stops propagation of data from obs 4, but what if there were no such data after obs 4?&amp;nbsp; When would propagation stop, if at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you show only only one subjid in your data.&amp;nbsp; You didn't say whether data should be propagated across subjects (probably not, but it would be good to have it stated).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In short, help us help you - by providing a sufficient description of the problem such that you won't have to answer lots of follow-up questions.&amp;nbsp; That's probably a more valuable skill to develop than sas coding, even in this forum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Apr 2021 14:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/731235#M227784</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-04T14:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I retain value in missing observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/732847#M228369</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any idea how I can get the missing observation where highlighted in seq variable 5&amp;amp;6, but it should not retain the values in seq 8 and 9 of my orignal post.&lt;/P&gt;
&lt;P&gt;I tried to use retain statement but it does not provide the output I want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am sharing another example below&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;-&amp;nbsp; I only want collap, count, collapse where highlighted in yellow. The reason behind is because I have collapsed dates where collapex =Y . All the dates associated with the collapsing should have collap = 1, count =1 or count =2 if a second collapsing of date has happened within same subject and collapse = Y.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nans_p_0-1618137004343.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57352i251563B2F4B8B604/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nans_p_0-1618137004343.png" alt="nans_p_0-1618137004343.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Hope this is clear. Apart from retain what is the best method I can use?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 10:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/732847#M228369</guid>
      <dc:creator>nans_p</dc:creator>
      <dc:date>2021-04-11T10:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I retain value in missing observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/732853#M228371</link>
      <description>&lt;P&gt;Please post your data in usable form, which means a data step with datalines, which we can copy/paste to our environment and submit.&lt;/P&gt;
&lt;P&gt;Test your data step code before posting to make sure it recreates a sufficient example of your data, and use the "little running man" button to open a code box into which you paste the code.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 13:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-retain-value-in-missing-observations/m-p/732853#M228371</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-11T13:42:01Z</dc:date>
    </item>
  </channel>
</rss>

