<?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: can someone help write a SAS proc Sql orSAS data step to get the last non blank value in a colum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925304#M364163</link>
    <description>&lt;P&gt;Under the assumption that you've got always at least one populated value per ID and month below variation to what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;proposed will only select the chosen month for analysis instead of all months up to the chosen month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month= Feb2024 ;

data want;
  set have(rename=(Parameter=P) where=(intck('month',"01&amp;amp;month."d,date)=0 ));
  by id;
  length Parameter $ 80;
  retain Parameter;
  if first.id then call missing(Parameter);
  if not missing(P) then Parameter=P;
  if last.id;
  drop P;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Apr 2024 01:51:25 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-04-23T01:51:25Z</dc:date>
    <item>
      <title>can someone help write a SAS proc Sql orSAS data step to get the last non blank value in a column ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925299#M364159</link>
      <description>&lt;DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;Input&lt;/STRONG&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;ID Date Parameter&lt;/P&gt;&lt;P&gt;1 1_feb-2024 -&lt;/P&gt;&lt;P&gt;1 28-feb-2024 x&lt;/P&gt;&lt;P&gt;1 10-mar-2024 -&lt;/P&gt;&lt;P&gt;1 20-Mar-2024 x&lt;/P&gt;&lt;P&gt;1 31-mar-2024 -&lt;/P&gt;&lt;P&gt;1 01-apr-2024 x&lt;/P&gt;&lt;P&gt;2 1-feb-2024 x&lt;/P&gt;&lt;P&gt;2 28-feb-2024 -&lt;/P&gt;&lt;P&gt;2 10-mar-2024 -&lt;/P&gt;&lt;P&gt;2 20-Mar-2024 -&lt;/P&gt;&lt;P&gt;2 31-mar-2024 x&lt;/P&gt;&lt;P&gt;2 10-apr-2024 x&lt;/P&gt;&lt;P&gt;2 30-apr-2024 -&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Output-&lt;/STRONG&gt;-Last populated value of the parameter prior to the month end.&lt;/P&gt;&lt;P&gt;So if I run my code as of Feb-2024 month end, the output should be&lt;/P&gt;&lt;P&gt;ID Date Parameter&lt;/P&gt;&lt;P&gt;1 28-feb-2024 x&lt;/P&gt;&lt;P&gt;2 28-feb-2024 x&lt;/P&gt;&lt;P&gt;So if I run my code as of Mar-2024 month end, the output should be&lt;/P&gt;&lt;P&gt;ID Date Parameter&lt;/P&gt;&lt;P&gt;1 31_mar-2024 x&lt;/P&gt;&lt;P&gt;2 31-mar-2024 x&lt;/P&gt;&lt;P&gt;So if I run my code as of Apr-2024 month end, the output should be&lt;/P&gt;&lt;P&gt;ID Date Parameter&lt;/P&gt;&lt;P&gt;1 1-Apr-2024 x&lt;/P&gt;&lt;P&gt;2 30-apr-2024 x&lt;/P&gt;&lt;P&gt;I tried the below, but it only gives me the last row, without considering month&lt;/P&gt;&lt;P&gt;data output;&lt;/P&gt;&lt;P&gt;update input(obs=0) input;&lt;/P&gt;&lt;P&gt;by ID;&lt;/P&gt;&lt;P&gt;data output;&lt;/P&gt;&lt;P&gt;update input(obs=0) input;&lt;/P&gt;&lt;P&gt;by ID; run;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 00:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925299#M364159</guid>
      <dc:creator>Swapnasis</dc:creator>
      <dc:date>2024-04-23T00:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: can someone help write a SAS proc Sql orSAS data step to get the last non blank value in a colum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925301#M364160</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Date :date11. Parameter $;
format Date date11.;
if Parameter='-' then call missing(Parameter);
cards;
1 1-feb-2024 -
1 28-feb-2024 x
1 10-mar-2024 -
1 20-Mar-2024 x
1 31-mar-2024 -
1 01-apr-2024 x
2 1-feb-2024 x
2 28-feb-2024 -
2 10-mar-2024 -
2 20-Mar-2024 -
2 31-mar-2024 x
2 10-apr-2024 x
2 30-apr-2024 -
;


%let month= Apr2024 ;

data want;
 set have(rename=(Parameter=P) where=(date&amp;lt;=%sysfunc(intnx(month,"01&amp;amp;month."d,0,e))));
 by id;
 length Parameter $ 80;
 retain Parameter;
 if first.id then call missing(Parameter);
 if not missing(P) then Parameter=P;
 if last.id;
 drop P;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Apr 2024 01:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925301#M364160</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-04-23T01:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: can someone help write a SAS proc Sql orSAS data step to get the last non blank value in a colum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925304#M364163</link>
      <description>&lt;P&gt;Under the assumption that you've got always at least one populated value per ID and month below variation to what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;proposed will only select the chosen month for analysis instead of all months up to the chosen month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month= Feb2024 ;

data want;
  set have(rename=(Parameter=P) where=(intck('month',"01&amp;amp;month."d,date)=0 ));
  by id;
  length Parameter $ 80;
  retain Parameter;
  if first.id then call missing(Parameter);
  if not missing(P) then Parameter=P;
  if last.id;
  drop P;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Apr 2024 01:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925304#M364163</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-23T01:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: can someone help write a SAS proc Sql orSAS data step to get the last non blank value in a colum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925306#M364164</link>
      <description>&lt;P&gt;Why did you include data after the stop date???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming the hyphens in your listing are supposed to be MISSING values then your data looks something like this one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID Date :date. Parameter $ ;
  format date date9.;
cards;
1 1_feb-2024 .
1 28-feb-2024 x
1 10-mar-2024 .
1 20-Mar-2024 x
1 31-mar-2024 .
1 01-apr-2024 x
2 1-feb-2024 x
2 28-feb-2024 .
2 10-mar-2024 .
2 20-Mar-2024 .
2 31-mar-2024 x
2 10-apr-2024 x
2 30-apr-2024 .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you only want to consider the data before the start of MARCH if want the data as of the end of FEBRUARY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  update have(obs=0) have;
  by id;
  where date &amp;lt; '01MAR2024'd ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    ID         Date    Parameter

 1      1    28FEB2024        x
 2      2    28FEB2024        x
&lt;/PRE&gt;
&lt;P&gt;To find the data as of some other point in time just change the date used in the WHERE statement.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 02:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925306#M364164</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-23T02:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: can someone help write a SAS proc Sql orSAS data step to get the last non blank value in a colum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925315#M364168</link>
      <description>Thanks ksharp.Appreciate it</description>
      <pubDate>Tue, 23 Apr 2024 03:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925315#M364168</guid>
      <dc:creator>Swapnasis</dc:creator>
      <dc:date>2024-04-23T03:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: can someone help write a SAS proc Sql orSAS data step to get the last non blank value in a colum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925316#M364169</link>
      <description>can this logic be written in proc sql, so that I can use the logic to pull data from database?</description>
      <pubDate>Tue, 23 Apr 2024 03:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925316#M364169</guid>
      <dc:creator>Swapnasis</dc:creator>
      <dc:date>2024-04-23T03:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: can someone help write a SAS proc Sql orSAS data step to get the last non blank value in a colum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925320#M364172</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
Yes. You can,
But it is very tough task for PROC SQL.
Pick up the right tool (data step) for this kind of task.
*/

data have;
input ID Date :date11. Parameter $;
format Date date11.;
if Parameter='-' then call missing(Parameter);
cards;
1 1-feb-2024 -
1 28-feb-2024 x
1 10-mar-2024 -
1 20-Mar-2024 x
1 31-mar-2024 -
1 01-apr-2024 x
2 1-feb-2024 x
2 28-feb-2024 -
2 10-mar-2024 -
2 20-Mar-2024 -
2 31-mar-2024 x
2 10-apr-2024 x
2 30-apr-2024 -
;


%let month= Apr2024 ;

proc sql;
create table want as
select a.*,Parameter
from
(
select distinct id,date from have 
 where date&amp;lt;=%sysfunc(intnx(month,"01&amp;amp;month."d,0,e)) 
  group by id
    having date=max(date)
) as a 
left join
(
select distinct id,Parameter from have 
 where date&amp;lt;=%sysfunc(intnx(month,"01&amp;amp;month."d,0,e)) and  Parameter is not missing
  group by id
       having date=max(date)
) as b
on a.id=b.id
;

quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Apr 2024 06:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-someone-help-write-a-SAS-proc-Sql-orSAS-data-step-to-get-the/m-p/925320#M364172</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-04-23T06:04:28Z</dc:date>
    </item>
  </channel>
</rss>

