<?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 to find a date that goes from Not Null to Null in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-a-date-that-goes-from-Not-Null-to-Null/m-p/953039#M42819</link>
    <description>&lt;P&gt;To do what your subject line literal says you would want something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if missing(pick_date)
    and (not missing(lag(pick_date)))
    and (apple_var = lag(apple_var))
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The last condition makes sure you don't compare pick_date values across apple varieties.&lt;/P&gt;
&lt;P&gt;It also means you cannot select an observation that has missing pick_date that is the first for this apple variety.&lt;/P&gt;
&lt;P&gt;And if you have multiple places where PICK_DATE transitioned from being present to being missing for the same apple variety all of those transitions would be selected.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Dec 2024 21:40:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-12-09T21:40:05Z</dc:date>
    <item>
      <title>How to find a date that goes from Not Null to Null</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-a-date-that-goes-from-Not-Null-to-Null/m-p/953026#M42815</link>
      <description>&lt;P&gt;Please be gentle - I'm new - using SAS 9.4&amp;nbsp; &amp;nbsp; &amp;nbsp; I'm trying to find the first date the Pick_Date is Null.&amp;nbsp; &amp;nbsp;Any assistance is appreciated!&amp;nbsp; Thanks in advance!!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what my data table looks like:&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="348"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="97"&gt;Table Orchard&amp;nbsp;&lt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
&lt;TD&gt;8/26/2024&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Granny&lt;/TD&gt;
&lt;TD&gt;8/26/2024&lt;/TD&gt;
&lt;TD&gt;8/27/2024&lt;/TD&gt;
&lt;TD&gt;8/27/2024&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Granny&lt;/TD&gt;
&lt;TD&gt;8/26/2024&lt;/TD&gt;
&lt;TD&gt;8/28/2024&lt;/TD&gt;
&lt;TD&gt;8/28/2024&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Granny&lt;/TD&gt;
&lt;TD&gt;8/26/2024&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;8/29/2024&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my desired output:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="335"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="97"&gt;Table Orchard&amp;nbsp;&lt;/TD&gt;
&lt;TD width="81"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="68"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="89"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Apple_Var&lt;/TD&gt;
&lt;TD&gt;Ready_Date&lt;/TD&gt;
&lt;TD&gt;Pick_Date&lt;/TD&gt;
&lt;TD&gt;Change_Date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Red_Del&lt;/TD&gt;
&lt;TD&gt;8/24/2024&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;8/28/2024&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Granny&lt;/TD&gt;
&lt;TD&gt;8/26/2024&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;8/29/2024&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 09 Dec 2024 21:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-a-date-that-goes-from-Not-Null-to-Null/m-p/953026#M42815</guid>
      <dc:creator>ScotchCat</dc:creator>
      <dc:date>2024-12-09T21:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a date that goes from Not Null to Null</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-a-date-that-goes-from-Not-Null-to-Null/m-p/953036#M42816</link>
      <description>&lt;P&gt;First in what sense?&lt;/P&gt;
&lt;P&gt;First sorted by what variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get what you showed you probably want the data sorted by APPLE_VAR and CHANGE_DATE and just find the first per APPLE_VAR that has missing value of PICK_DATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First let's convert your LISTING into an actual DATASET so we have something to work from.&amp;nbsp; Let's display the dates with a format that will not confuse half of our audience.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  input Apple_Var :$10. (Ready_Date Pick_Date Change_Date) (:mmddyy.);
  format Ready_Date Pick_Date Change_Date date9.;
cards;
Red_Del 8/24/2024 8/24/2024 8/24/2024
Red_Del 8/24/2024 8/25/2024 8/25/2024
Red_Del 8/24/2024 8/26/2024 8/26/2024
Red_Del 8/24/2024 8/27/2027 8/27/2024
Red_Del 8/24/2024 .  8/28/2024
Granny 8/26/2024 8/26/2024 8/26/2024
Granny 8/26/2024 8/27/2024 8/27/2024
Granny 8/26/2024 8/28/2024 8/28/2024
Granny 8/26/2024 .  8/29/2024
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will need to make sure the data is sorted properly so we can use BY statement in our data step.&lt;/P&gt;
&lt;P&gt;Note that since your example only has TWO apple varieties you could get it to work without the sort by using the DESCENDING keyword in the BY statement to let the data step know that you have the apple varieties in descending alphabetical order.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=HAVE;
  by apple_var change_date;
run;

data WANT;
  set have;
  by apple_var change_date;
  where missing(pick_date);
  if first.apple_var;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;       Apple_        Ready_                   Change_
Obs      Var           Date    Pick_Date         Date

 1     Granny     26AUG2024            .    29AUG2024
 2     Red_Del    24AUG2024            .    28AUG2024

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 21:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-a-date-that-goes-from-Not-Null-to-Null/m-p/953036#M42816</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-09T21:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a date that goes from Not Null to Null</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-a-date-that-goes-from-Not-Null-to-Null/m-p/953037#M42817</link>
      <description>&lt;P&gt;Since you appear to want to process data in the order the data set is currently then that would mean to use a data set in SAS as that processes records in order.&lt;/P&gt;
&lt;P&gt;You did not state but seem to imply that you want the result based on the grouping value of a variable named Apple_var.&lt;/P&gt;
&lt;P&gt;What you did not say explicitly what to do in the cases of:&lt;/P&gt;
&lt;P&gt;1) the only observations for pick_date with missing do not have any "prior" records with none-missing values&lt;/P&gt;
&lt;P&gt;2) if there are no missing Pick_date values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a BY statement to process by the values of a variable. This assumes the data is sorted by that variable. If the data is not actually sorted but is grouped by that variable (your example Red_Del would not come before Granny by sort order) you can use the keyword NOTSORTED to prevent an error. Since you are looking for a "first and only" you need something to help identify if it is the first. That would typically call for flag variable that is RETAINED, keeps the same value from observation to observation unless reset to indicate when to output the needed records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BEST is to provide example data in the form of a working data step and paste into a text box opened with the &amp;lt;/&amp;gt; icon that appears above the message window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So something like this, creates a data set hopefully similar to yours and then selects the observations.&lt;/P&gt;
&lt;PRE&gt;data have;
    input Apple_Var $ 	Ready_Date :mmddyy10.	Pick_Date :mmddyy10.	Change_Date  :mmddyy10. ;
    format Ready_Date :mmddyy10.	Pick_Date :mmddyy10.	Change_Date  :mmddyy10. ;
datalines;
Red_Del 	8/24/2024 	8/24/2024 	8/24/2024
Red_Del 	8/24/2024 	8/25/2024 	8/25/2024
Red_Del 	8/24/2024 	8/26/2024 	8/26/2024
Red_Del 	8/24/2024 	8/27/2027 	8/27/2024
Red_Del 	8/24/2024 	.        	8/28/2024
Granny 	8/26/2024 	8/26/2024 	8/26/2024
Granny 	8/26/2024 	8/27/2024 	8/27/2024
Granny 	8/26/2024 	8/28/2024 	8/28/2024
Granny 	8/26/2024 	.        	8/29/2024
;

data want;
   set have;
   by apple_var notsorted;
   retain found;
   if first.apple_var then found=0 ;
   if missing(pick_date) and found=0 then do;
      found=1;
      output;
   end;
   drop found;
run;&lt;/PRE&gt;
&lt;P&gt;This doesn't handle the cases where the first observations all have missing pick_dates though.&lt;/P&gt;
&lt;P&gt;The BY creates a temporary variable for each variable on the BY statement that indicate first or last value of the group and are 1/0 coded for true/false.&lt;/P&gt;
&lt;P&gt;The Output statement makes only explicitly stated output records to write to the output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 21:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-a-date-that-goes-from-Not-Null-to-Null/m-p/953037#M42817</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-12-09T21:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a date that goes from Not Null to Null</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-a-date-that-goes-from-Not-Null-to-Null/m-p/953038#M42818</link>
      <description>Thank you!! I really appreciate - and learning so much from this community!</description>
      <pubDate>Mon, 09 Dec 2024 21:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-a-date-that-goes-from-Not-Null-to-Null/m-p/953038#M42818</guid>
      <dc:creator>ScotchCat</dc:creator>
      <dc:date>2024-12-09T21:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a date that goes from Not Null to Null</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-a-date-that-goes-from-Not-Null-to-Null/m-p/953039#M42819</link>
      <description>&lt;P&gt;To do what your subject line literal says you would want something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if missing(pick_date)
    and (not missing(lag(pick_date)))
    and (apple_var = lag(apple_var))
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The last condition makes sure you don't compare pick_date values across apple varieties.&lt;/P&gt;
&lt;P&gt;It also means you cannot select an observation that has missing pick_date that is the first for this apple variety.&lt;/P&gt;
&lt;P&gt;And if you have multiple places where PICK_DATE transitioned from being present to being missing for the same apple variety all of those transitions would be selected.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 21:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-a-date-that-goes-from-Not-Null-to-Null/m-p/953039#M42819</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-09T21:40:05Z</dc:date>
    </item>
  </channel>
</rss>

