<?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: getting the last known status from multiple time points in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/getting-the-last-known-status-from-multiple-time-points/m-p/804680#M316911</link>
    <description>&lt;P&gt;I fixed some trouble with the fake data you posted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data fake_data;
   length patId $ 4 visit_1-visit_5 8;
   input patID visit_1 - visit_5;
 datalines;
 1693 1 1 . . 0
 0659 0 . . 1 0
 0389 1 0 . 1 0
 0744 1 . 0 1 0
 1129 0 1 . . 1
 1003 0 0 1 . 1
 0734 1 . 0 . 1
 1345 1 . 1 . 0
 0219 0 . . 1 1
 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Maybe something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set fake_data;
   
   length lks_v2 - lks_v5 8;
   array v visit_2 - visit_5;
   array b lks_v2 - lks_v5;
   
   hasOne = 0;
     
   do i = dim(b) to 1 by -1;
      b[i] = v[i] and not hasOne;
      hasOne = b[i];
   end;
   
   drop i hasOne;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Mar 2022 07:15:04 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2022-03-29T07:15:04Z</dc:date>
    <item>
      <title>getting the last known status from multiple time points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-the-last-known-status-from-multiple-time-points/m-p/804673#M316905</link>
      <description>&lt;P&gt;I have patient data where they come in on the first visit and are scheduled follow up visits. The values are binary except when they miss a visit (blank). I would like to create 4 new variables for each visit that will be the last known non-missing status from the last visit. So from the fake data below, for the last patient (0219):&lt;/P&gt;
&lt;P&gt;lks_v2 = 0&lt;/P&gt;
&lt;P&gt;lks_v3 = 0&lt;/P&gt;
&lt;P&gt;lks_v4 = 0&lt;/P&gt;
&lt;P&gt;lks_v5 = 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know I can do this with a bunch of if statements but is there a more elegant way? I was thinking to use coalesce statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fake_data;

input patID $ 1-4
	visit_1 $ 6
	visit_2 $ 8
	visit_3 $ 10
	visit_4 $ 12
	visit_5 $ 14
;

datalines;
1693 1 1 . . 0
0659 0 . . 1 0
0389 1 0 . 1 0
0744 1 . 0 1 0
1129 0 1 . . 1
1003 0 0 1 . 1
0734 1 . 0 . 1
1345 1 . 1 . 0
0219 0 . . 1 1
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 06:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-the-last-known-status-from-multiple-time-points/m-p/804673#M316905</guid>
      <dc:creator>axescot78</dc:creator>
      <dc:date>2022-03-29T06:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: getting the last known status from multiple time points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-the-last-known-status-from-multiple-time-points/m-p/804680#M316911</link>
      <description>&lt;P&gt;I fixed some trouble with the fake data you posted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data fake_data;
   length patId $ 4 visit_1-visit_5 8;
   input patID visit_1 - visit_5;
 datalines;
 1693 1 1 . . 0
 0659 0 . . 1 0
 0389 1 0 . 1 0
 0744 1 . 0 1 0
 1129 0 1 . . 1
 1003 0 0 1 . 1
 0734 1 . 0 . 1
 1345 1 . 1 . 0
 0219 0 . . 1 1
 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Maybe something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set fake_data;
   
   length lks_v2 - lks_v5 8;
   array v visit_2 - visit_5;
   array b lks_v2 - lks_v5;
   
   hasOne = 0;
     
   do i = dim(b) to 1 by -1;
      b[i] = v[i] and not hasOne;
      hasOne = b[i];
   end;
   
   drop i hasOne;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 07:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-the-last-known-status-from-multiple-time-points/m-p/804680#M316911</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-03-29T07:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: getting the last known status from multiple time points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-the-last-known-status-from-multiple-time-points/m-p/804792#M316968</link>
      <description>&lt;P&gt;this didn't work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how do I specify going to the prior element? v[i-1] did not work.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 15:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-the-last-known-status-from-multiple-time-points/m-p/804792#M316968</guid>
      <dc:creator>axescot78</dc:creator>
      <dc:date>2022-03-29T15:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: getting the last known status from multiple time points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-the-last-known-status-from-multiple-time-points/m-p/804854#M316977</link>
      <description>&lt;P&gt;I found this to work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
	set fake_data;	
	
	/* assigns first non-missing follow up values */
	do;
		lks_v2 = visit_1;
		lks_v3 = coalesce(of visit_2 - visit_1);
		lks_v4 = coalesce(of visit_3 - visit_1);
		lks_v5 = coalesce(of visit_4 - visit_1);
	end;
	
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Mar 2022 17:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-the-last-known-status-from-multiple-time-points/m-p/804854#M316977</guid>
      <dc:creator>axescot78</dc:creator>
      <dc:date>2022-03-29T17:45:14Z</dc:date>
    </item>
  </channel>
</rss>

