<?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: Find the first date with having non-missing data for each group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799887#M314577</link>
    <description>&lt;P&gt;Thank you all for helping.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;: I follow your suggestion for the other topic and I think I get the idea.&lt;/P&gt;
&lt;P&gt;Will post it once it is done.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
    <pubDate>Thu, 03 Mar 2022 15:40:29 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2022-03-03T15:40:29Z</dc:date>
    <item>
      <title>Find the first date with having non-missing data for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799877#M314571</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I try to find the first date (row) with non-missing value for each id.&lt;/P&gt;
&lt;P&gt;So in my sample data below, id 1 first valid date is 1. and id 2 first valid date is 3.&lt;/P&gt;
&lt;P&gt;Still haven't figure out a good way to do it.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
  input date id v1;
datalines;
1 1 30
2 1 .
3 1 20
1 2 .
2 2 .
3 2 1
4 2 6
5 2 .
;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799877#M314571</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-03-03T15:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first date with having non-missing data for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799880#M314573</link>
      <description>&lt;P&gt;What do you expect the output to look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is "date" ever missing? If so, what then?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799880#M314573</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-03T15:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first date with having non-missing data for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799884#M314575</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select * 
  from have
  where not missing(v1)
  group by id, date
  having min(date)
  order by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799884#M314575</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-03-03T15:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first date with having non-missing data for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799886#M314576</link>
      <description>&lt;P&gt;Assuming you meant non-missing value of V1 then just use BY group processing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  where not missing(v1);
  by id date;
  if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799886#M314576</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-03T15:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first date with having non-missing data for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799887#M314577</link>
      <description>&lt;P&gt;Thank you all for helping.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;: I follow your suggestion for the other topic and I think I get the idea.&lt;/P&gt;
&lt;P&gt;Will post it once it is done.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799887#M314577</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-03-03T15:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first date with having non-missing data for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799889#M314578</link>
      <description>&lt;P&gt;Given your data is already sorted by id/date, this is a simple task:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
  input date id v1;
datalines;
1 1 30
2 1 .
3 1 20
1 2 .
2 2 .
3 2 1
4 2 6
5 2 .
;

data want;
  set have (where=(not missing(v1)));
  by id;
  if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I take it that the "non-missing value" criterion refers to V1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although I assume data are sorted by ID/DATE, they really only have to be sorted by DATE within each ID.&amp;nbsp; The ID's can be in any order.&amp;nbsp; In this case you would change "BY ID;" to "BY ID NOTSORTED;".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And as to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;question about missing dates - you could revise the WHERE parameter to ignore missing dates:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  set have (where=(not missing(date) and not missing(v1)));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-date-with-having-non-missing-data-for-each-group/m-p/799889#M314578</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-03T15:40:54Z</dc:date>
    </item>
  </channel>
</rss>

