<?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: Creating beginning and end date by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-beginning-and-end-date-by-group/m-p/559053#M156074</link>
    <description>&lt;P&gt;First thing is likely not to treat "dates" as character variables.&lt;/P&gt;
&lt;PRE&gt;data have;  
   input Scenario $ Date :yymmdd.;
   format date date9.;
   datalines;
A  20180601
A  20180701
A  20180801
B  20180701
B  20180801
C  20180601
C  20180701
;
run;
&lt;/PRE&gt;
&lt;P&gt;Since you state that you have multiple variables that you need to "group by" then you should provide example data with multiple variables and what the "grouping by" would look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I actually don't see any "grouping" going on but adding records to have common values. And if there are other variables involved the approaches need to know what would be going on with other variables' values.&lt;/P&gt;</description>
    <pubDate>Wed, 15 May 2019 16:24:53 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-05-15T16:24:53Z</dc:date>
    <item>
      <title>Creating beginning and end date by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-beginning-and-end-date-by-group/m-p/559046#M156070</link>
      <description>&lt;P&gt;I want create a starting date and ending date by group of variables.&amp;nbsp; Below is an abbreviated example of what I want.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;  
   input Scenario $ Date $;
   datalines;
A  20180601
A  20180701
A  20180801
B  20180701
B  20180801
C  20180601
C  20180701
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;  
   input Scenario $ Date $;
   datalines;
A  20180601
A  20180701
A  20180801
B  20180601
B  20180701
B  20180801
C  20180601
C  20180701
C  20180801
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to figure out for each scenario A, B, C how to make the first date&amp;nbsp;&lt;CODE class=" language-sas"&gt;20180601 and the last date&amp;nbsp;20180801?&amp;nbsp; My real problem has several variables I need to group by.&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-beginning-and-end-date-by-group/m-p/559046#M156070</guid>
      <dc:creator>dsriggs11</dc:creator>
      <dc:date>2019-05-15T16:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating beginning and end date by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-beginning-and-end-date-by-group/m-p/559053#M156074</link>
      <description>&lt;P&gt;First thing is likely not to treat "dates" as character variables.&lt;/P&gt;
&lt;PRE&gt;data have;  
   input Scenario $ Date :yymmdd.;
   format date date9.;
   datalines;
A  20180601
A  20180701
A  20180801
B  20180701
B  20180801
C  20180601
C  20180701
;
run;
&lt;/PRE&gt;
&lt;P&gt;Since you state that you have multiple variables that you need to "group by" then you should provide example data with multiple variables and what the "grouping by" would look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I actually don't see any "grouping" going on but adding records to have common values. And if there are other variables involved the approaches need to know what would be going on with other variables' values.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-beginning-and-end-date-by-group/m-p/559053#M156074</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-15T16:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating beginning and end date by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-beginning-and-end-date-by-group/m-p/559068#M156085</link>
      <description>&lt;P&gt;So you want all groups to have all of the dates that appear in your data?&lt;/P&gt;
&lt;P&gt;So if there are three variables that define the groups then something like this will make sure that all groups have all of the dates.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create skeleton as
select *
from (select distinct var1,var2,var3 from have)
   , (select distinct date from have)
order by var1,var2,var3,date
;
quit;
data want ;
 merge skeleton have;
 by var1 var2 var3 date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If instead you want to have all groups have every month between the min and max date for all groups then you need to first generate that list.&amp;nbsp; This time let's show a method that doesn't use PROC SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have ;
  var date ;
  output dates min=min_date max=max_date;
run;

data skeleton ;
  set have (keep=var1 var2 var3 date);
  by var1 var2 var3;
  if first.var3;
  if _n_=1 then set dates;
  do i=0 to intck('month',min_date,max_date);
    date=intnx('month',min_date,i);
    output;
  end;
  drop i min_date max_date;
run;

data want;
  merge skeleton have;
  by var1 var2 var3 date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 May 2019 17:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-beginning-and-end-date-by-group/m-p/559068#M156085</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-15T17:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating beginning and end date by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-beginning-and-end-date-by-group/m-p/559092#M156094</link>
      <description>&lt;P&gt;Brilliant! Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 18:30:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-beginning-and-end-date-by-group/m-p/559092#M156094</guid>
      <dc:creator>dsriggs11</dc:creator>
      <dc:date>2019-05-15T18:30:58Z</dc:date>
    </item>
  </channel>
</rss>

