<?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 how to populate a date if day or month or year missing ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463548#M118109</link>
    <description>&lt;P&gt;&lt;BR /&gt;data dates;&lt;BR /&gt;input sdate $10.;&lt;BR /&gt;cards;&lt;BR /&gt;2009-10-14&lt;BR /&gt;2010-12-24&lt;BR /&gt;2001-03&lt;BR /&gt;2006-06&lt;BR /&gt;2012&lt;BR /&gt;2002-03-27&lt;BR /&gt;2003-02-03&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if month is missing replace it with 01&lt;BR /&gt;if day is missing replace it with 01&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;need output like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2009-10-14&lt;BR /&gt;2010-12-24&lt;BR /&gt;2001-03-01&lt;BR /&gt;2006-06-01&lt;BR /&gt;2012-01-01&lt;BR /&gt;2002-03-27&lt;BR /&gt;2003-02-03&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 19 May 2018 17:25:10 GMT</pubDate>
    <dc:creator>rajeshV89</dc:creator>
    <dc:date>2018-05-19T17:25:10Z</dc:date>
    <item>
      <title>how to populate a date if day or month or year missing ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463548#M118109</link>
      <description>&lt;P&gt;&lt;BR /&gt;data dates;&lt;BR /&gt;input sdate $10.;&lt;BR /&gt;cards;&lt;BR /&gt;2009-10-14&lt;BR /&gt;2010-12-24&lt;BR /&gt;2001-03&lt;BR /&gt;2006-06&lt;BR /&gt;2012&lt;BR /&gt;2002-03-27&lt;BR /&gt;2003-02-03&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if month is missing replace it with 01&lt;BR /&gt;if day is missing replace it with 01&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;need output like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2009-10-14&lt;BR /&gt;2010-12-24&lt;BR /&gt;2001-03-01&lt;BR /&gt;2006-06-01&lt;BR /&gt;2012-01-01&lt;BR /&gt;2002-03-27&lt;BR /&gt;2003-02-03&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 17:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463548#M118109</guid>
      <dc:creator>rajeshV89</dc:creator>
      <dc:date>2018-05-19T17:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a date if day or month or year missing ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463553#M118110</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dates;
input sdate $10.;
cards;
2009-10-14
2010-12-24
2001-03
2006-06
2012
2002-03-27
2003-02-03
;
run;

data want;
set dates;
new_date=input(sdate,anydtdte21.);
if missing(new_date) then new_date=mdy(1,1,sdate) ;
format new_date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 May 2018 17:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463553#M118110</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-19T17:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a date if day or month or year missing ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463556#M118113</link>
      <description>&lt;P&gt;You already have a character variable with a length of $10.&amp;nbsp; If you want to keep it that way, you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sdate = catt(sdate, '-01-01');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any extra characters beyond the length of 10 won't fit, and will be dropped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you prefer a numeric date that takes advantage of SAS's date-handling capabilities, you would need to convert that result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sasdate = input(sdate, yymmdd10.);&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 18:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463556#M118113</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-19T18:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a date if day or month or year missing ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463564#M118117</link>
      <description>&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;You could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options datestyle=ymd;
data dates;
  infile cards truncover;
  informat sdate anydtdte10.;
  input @;
  if length(_infile_) eq 4 then _infile_=catt(_infile_,'-01');
  else if length(_infile_) eq 5 then _infile_=catt('2018-',_infile_);
  else if length(_infile_) lt 2 then _infile_='2018-01-01';
  input sdate;
  format sdate date9.;
  cards;
2009-10-14
2010-12-24
2001-03
2006-06

09-07
2012
2002-03-27
2003-02-03
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, you never mentioned what year you want populated in case year is missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 19:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463564#M118117</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-05-19T19:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a date if day or month or year missing ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463623#M118142</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dates;
input sdate $10.;
year=scan(sdate,1,'-','m');
month=coalescec(scan(sdate,2,'-','m'),'01');
day=coalescec(scan(sdate,3,'-','m'),'01');
want=input(cats(year,month,day),yymmdd10.);
format want yymmdd10.;
cards;
2009-10-14
2010-12-24
2001-03
2006-06
2012
2002-03-27
2003-02-03
;
run;
proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 May 2018 10:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463623#M118142</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-05-20T10:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a date if day or month or year missing ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463974#M118278</link>
      <description>&lt;P&gt;DATA TEMP(DROP=TEMP_MONTH TEMP_DATE);&lt;BR /&gt;input sdate $10.;&lt;BR /&gt;Year=SCAN(sdate,1,'-');&lt;BR /&gt;TEMP_Month=SCAN(sdate,2,'-');&lt;BR /&gt;TEMP_Date=SCAN(sdate,3,'-');&lt;/P&gt;&lt;P&gt;IF TEMP_MONTH NE . THEN MONTH=TEMP_MONTH;&lt;BR /&gt;ELSE MONTH='01';&lt;/P&gt;&lt;P&gt;IF TEMP_Date NE . THEN DATE=TEMP_Date;&lt;BR /&gt;ELSE DATE='01';&lt;/P&gt;&lt;P&gt;FINAL_DATE= MDY(MONTH,DATE,YEAR);&lt;BR /&gt;FORMAT FINAL_DATE worddate15.;&lt;BR /&gt;cards;&lt;BR /&gt;2009-10-14&lt;BR /&gt;2010-12-24&lt;BR /&gt;2001-03&lt;BR /&gt;2006-06&lt;BR /&gt;2012&lt;BR /&gt;2002-03-27&lt;BR /&gt;2003-02-03&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2018 08:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463974#M118278</guid>
      <dc:creator>mahesh146</dc:creator>
      <dc:date>2018-05-22T08:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a date if day or month or year missing ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463993#M118283</link>
      <description>&lt;P&gt;here i hot one solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;input sdate $10.;&lt;BR /&gt;format sdate_new yymmdd10.;&lt;BR /&gt;sdate_new=input(sdate,nd8601da.);&lt;BR /&gt;cards;&lt;BR /&gt;2009-10-14&lt;BR /&gt;2010-12-24&lt;BR /&gt;2001-03&lt;BR /&gt;2006-06&lt;BR /&gt;2012&lt;BR /&gt;2002-03-27&lt;BR /&gt;2003-02-03&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2018 09:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-date-if-day-or-month-or-year-missing/m-p/463993#M118283</guid>
      <dc:creator>rajeshV89</dc:creator>
      <dc:date>2018-05-22T09:38:24Z</dc:date>
    </item>
  </channel>
</rss>

