BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HannaZhang
Obsidian | Level 7

Dears,

   I have a partial date like "2002" ,Is there any function that can fill in "2002" as "2002-01-01"?  And there are similar ones,fill in "2002-01-01T01" as "2002-01-01T01:00"

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

For the partial date question, use the B8601DA Informat 

 

data _null_;
   dt1 = "2002";
   dt2 = input(dt1, B8601DA.);
   put dt2 yymmdd10.;
run;

 

For the partial datetime question, use the B8601DT informat

 

data _null_;
   dt1 = "2002-01-01";
   dt2 = input(dt1, B8601DT.);
   put dt2 E8601DT.;
run;

View solution in original post

8 REPLIES 8
andreas_lds
Jade | Level 19

Afaik no such function exists. You could use mdy to create a date when you have the year, only.

PeterClemmensen
Tourmaline | Level 20

For the partial date question, use the B8601DA Informat 

 

data _null_;
   dt1 = "2002";
   dt2 = input(dt1, B8601DA.);
   put dt2 yymmdd10.;
run;

 

For the partial datetime question, use the B8601DT informat

 

data _null_;
   dt1 = "2002-01-01";
   dt2 = input(dt1, B8601DT.);
   put dt2 E8601DT.;
run;
HannaZhang
Obsidian | Level 7
Your solution is very helpful THX!
blueskyxyz
Lapis Lazuli | Level 10
is there an informat to treat '2017' as '2017-12-31', and treat '2017-06' as '2017-06-30', , and treat '2017-05' as '2017-05-31'?
blueskyxyz
Lapis Lazuli | Level 10
ok, thanks, I didn't find such an informat in the book 'The Essential Guide to SAS® Dates and Times, Second Edition'. wish have one informat to impute partial date using different methods in the future...
HannaZhang
Obsidian | Level 7
THX , Draycut found mea way out

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2170 views
  • 2 likes
  • 5 in conversation