<?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: LOCF in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895595#M353853</link>
    <description>&lt;P&gt;Can you show the output data you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For simple last obs carry forward, you probably want to use the first value per ID.&amp;nbsp; And after that, use the value of SBP if SBP is not a missing value.&amp;nbsp; You can do that like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lf ;
  set sorted ;
  retain lo;
  by id visit ;
  if first.id then lo = sbp ;
  else if not missing(sbp) then lo=sbp ;
run ;

proc print ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I assume BOCF and WOCF are something like "best" and "worst" ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you could take above and adapt it.&amp;nbsp; The ELSE statement would compare the value of SBP to the value of LO and then decide whether or not to update the value of LO.&lt;/P&gt;</description>
    <pubDate>Sun, 24 Sep 2023 18:53:01 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2023-09-24T18:53:01Z</dc:date>
    <item>
      <title>LOCF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895591#M353852</link>
      <description>&lt;P&gt;data ONE ;&lt;BR /&gt;input id visit sbp ;&lt;BR /&gt;cards ;&lt;BR /&gt;101 10 95&lt;BR /&gt;101 20 .&lt;BR /&gt;101 30 90&lt;BR /&gt;102 10 100&lt;BR /&gt;102 20 105&lt;BR /&gt;102 30 .&lt;BR /&gt;103 10 90&lt;BR /&gt;103 20 90&lt;BR /&gt;103 30 115&lt;BR /&gt;104 10 .&lt;BR /&gt;104 20 100&lt;BR /&gt;104 30 .&lt;BR /&gt;104 40 105&lt;BR /&gt;;&lt;BR /&gt;proc sort data = one out = sorted ; by id visit ;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want LOCF BOCF WOCF for the above data I tried my code but I didn't get the desired output, Please any anyone help me write code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;Here is the code ;&lt;/DIV&gt;
&lt;DIV&gt;data lf ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;set sorted ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;retain lo;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;by id visit ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if first.id&amp;nbsp; and sbp = . then lo = . ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else do ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if id ne . then lo = sbp ;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else sbp = lo ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;run;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Need output like below :&lt;/P&gt;
&lt;P&gt;LOCF means&amp;nbsp;Last observation carryforward&lt;/P&gt;
&lt;P&gt;BOCF means Baseline&amp;nbsp;observation carryforward&amp;nbsp; (Here baseline visit as 10)&lt;/P&gt;
&lt;P&gt;WOCF means Worst&amp;nbsp;observation carryforward&lt;/P&gt;
&lt;P&gt;Obs&amp;nbsp; &amp;nbsp; id&amp;nbsp; &amp;nbsp; &amp;nbsp;visit&amp;nbsp; &amp;nbsp; sbp&amp;nbsp; &amp;nbsp; &amp;nbsp;locf&amp;nbsp; &amp;nbsp; &amp;nbsp;bocf&amp;nbsp; &amp;nbsp; &amp;nbsp;wocf&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 01&amp;nbsp; &amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;95&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;95&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 95&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;95 &lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;95&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 95&amp;nbsp; &amp;nbsp; &amp;nbsp; 95 &lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90&amp;nbsp; &amp;nbsp; &amp;nbsp; 90 &lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; 100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp;100 &lt;BR /&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; 105&amp;nbsp; &amp;nbsp; &amp;nbsp;105&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;105&amp;nbsp; &amp;nbsp; 105 &lt;BR /&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 105&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100&amp;nbsp; &amp;nbsp;105 &lt;BR /&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; 90&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 90&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90 &lt;BR /&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&amp;nbsp; &amp;nbsp; &amp;nbsp; 90&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 90&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90 &lt;BR /&gt;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;115&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;115&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;115&amp;nbsp; &amp;nbsp; &amp;nbsp; 115 &lt;BR /&gt;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&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; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 105&lt;BR /&gt;11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; 100&amp;nbsp; &amp;nbsp; &amp;nbsp;100 &lt;BR /&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;105&lt;BR /&gt;13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40&amp;nbsp; &amp;nbsp;105&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 105&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;105&amp;nbsp; &amp;nbsp; &amp;nbsp;105&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 01:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895591#M353852</guid>
      <dc:creator>112211</dc:creator>
      <dc:date>2023-09-25T01:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: LOCF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895595#M353853</link>
      <description>&lt;P&gt;Can you show the output data you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For simple last obs carry forward, you probably want to use the first value per ID.&amp;nbsp; And after that, use the value of SBP if SBP is not a missing value.&amp;nbsp; You can do that like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lf ;
  set sorted ;
  retain lo;
  by id visit ;
  if first.id then lo = sbp ;
  else if not missing(sbp) then lo=sbp ;
run ;

proc print ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I assume BOCF and WOCF are something like "best" and "worst" ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you could take above and adapt it.&amp;nbsp; The ELSE statement would compare the value of SBP to the value of LO and then decide whether or not to update the value of LO.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Sep 2023 18:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895595#M353853</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-09-24T18:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: LOCF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895597#M353855</link>
      <description>&lt;P&gt;You haven't provided any definitions of what you mean by LOCF, BOCF and WOCF. We need those before we can help code for them.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Sep 2023 18:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895597#M353855</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-09-24T18:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: LOCF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895607#M353860</link>
      <description>&lt;P&gt;LOCF (presumably "last" observation carried forward) typically means you want to carry forward the most recent non-missing value of a variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess BOCF and WOCF mean "best" and "worst" observation carried forward.&amp;nbsp; If "best" is highest, and "worst" is lowest, then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dm 'clear log';
data ONE ;
  input id visit sbp ;
cards ;
101 10 95
101 20 .
101 30 90
102 10 100
102 20 105
102 30 .
103 10 90
103 20 90
103 30 115
104 10 .
104 20 100
104 30 .
104 40 105
run;

data want;
  set one;
  by id visit;

  retain locf bocf wocf;
  locf=ifn(first.id,.,coalesce(lag(sbp),locf));
  bocf=ifn(first.id,.,max(bocf,locf));
  wocf=ifn(first.id,.,min(wocf,locf));
run;
proc print;
  id id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Sep 2023 22:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895607#M353860</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-24T22:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: LOCF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895609#M353861</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;I don't think that logic works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Those goofy IFN,IFC functions never make much sense to me (ripoffs from EXCEL I think).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If think you are looking for something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set one;
  by id visit;
  retain locf bocf wocf;
  if first.id then call missing(locf,bocf,wocf);
  locf=coalesce(sbp,locf);
  bocf=max(bocf,locf);
  wocf=min(wocf,locf);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;id=101

visit    sbp    locf    bocf    wocf

  10      95     95      95      95
  20       .     95      95      95
  30      90     90      95      90


id=102

visit    sbp    locf    bocf    wocf

  10     100     100     100     100
  20     105     105     105     100
  30       .     105     105     100


id=103

visit    sbp    locf    bocf    wocf

  10      90      90      90     90
  20      90      90      90     90
  30     115     115     115     90


id=104

visit    sbp    locf    bocf    wocf

  10       .       .       .       .
  20     100     100     100     100
  30       .     100     100     100
  40     105     105     105     100
&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Sep 2023 22:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895609#M353861</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-24T22:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: LOCF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895616#M353863</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;I don't think that logic works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Those goofy IFN,IFC functions never make much sense to me (ripoffs from EXCEL I think).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If think you are looking for something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set one;
  by id visit;
  retain locf bocf wocf;
  if first.id then call missing(locf,bocf,wocf);
  locf=coalesce(sbp,locf);
  bocf=max(bocf,locf);
  wocf=min(wocf,locf);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, I took the OP's request as defining "carry-forward" as excluding the current observation, which I should have clearly stated.&amp;nbsp; And which is also the reason my results differed from yours.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But even if that assumption is wrong, I'm still a fan of the IFN and IFC functions - for good reason.&amp;nbsp; They are particularly beneficial for situations such as conditionally retrieving lags.&amp;nbsp; &amp;nbsp;Since IFN and IFC evaluate both of the alternative return expressions, they always update the lag queue in those expressions, even if the lag is not the returned value.&amp;nbsp; This allows the replacement of these 4 lines&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;_tempvar=lag(x);
if some-condition then result=_tempvar;
else result=y;
drop _tempvar;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with this single line&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;result=ifn(some-condition,lag(x),y);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 16:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895616#M353863</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-25T16:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: LOCF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895648#M353869</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Assuming I understood what you mean.*/
data ONE ;
input id visit sbp ;
cards ;
101 10 95
101 20 .
101 30 90
102 10 100
102 20 105
102 30 .
103 10 90
103 20 90
103 30 115
104 10 .
104 20 100
104 30 .
104 40 105
;

data want;
 do until(last.id);
  set one;
  by id;
  if first.id then baseline=sbp;
  max=max(max,sbp);
 end;
 do until(last.id);
  set one;
  by id;
  if not missing(sbp) then locf=sbp;
  bocf=coalesce(sbp,baseline);
  wocf=coalesce(sbp,max);
  output;
 end;
 drop max baseline;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Sep 2023 11:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/895648#M353869</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-09-25T11:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: LOCF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/920501#M362523</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*Assuming I understood what you mean.*/
data ONE ;
input id visit sbp ;
cards ;
101 10 95
101 20 .
101 30 90
102 10 100
102 20 105
102 30 .
103 10 90
103 20 90
103 30 115
104 10 .
104 20 100
104 30 .
104 40 105
;

data want;
 do until(last.id);
  set one;
  by id;
  if first.id then baseline=sbp;
  max=max(max,sbp);
 end;
 do until(last.id);
  set one;
  by id;
  if not missing(sbp) then locf=sbp;
  bocf=coalesce(sbp,baseline);
  wocf=coalesce(sbp,max);
  output;
 end;
 drop max baseline;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Thankyou, it helped me in understanding my queries. &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 19:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOCF/m-p/920501#M362523</guid>
      <dc:creator>allenebrick</dc:creator>
      <dc:date>2024-03-15T19:12:48Z</dc:date>
    </item>
  </channel>
</rss>

