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

My sas dataset has this below date format, format $21 informat $21

Could any one help me easiest way to convert this to mmddyy10.?

Date

2002-01-10 00:00:00.0
2002-03-15 00:00:00.0
2002-04-23 00:00:00.0

Appreciate your help in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Since you imported it as character, as shown by $21 informat, you have two basic choices:

Reimport the data with a method that allows you to force the import format or create a new variable to hold the data value

To add a date only  variable:

data want;

     set have;

     SASdate = input(date,yymmdd10.);

     format SASDate mmddyy10.;

run;

View solution in original post

4 REPLIES 4
ballardw
Super User

Since you imported it as character, as shown by $21 informat, you have two basic choices:

Reimport the data with a method that allows you to force the import format or create a new variable to hold the data value

To add a date only  variable:

data want;

     set have;

     SASdate = input(date,yymmdd10.);

     format SASDate mmddyy10.;

run;

amahamud77
Calcite | Level 5

Thanks a lot! that worked for me. A

PGStats
Opal | Level 21

$21. is a CHARACTER format, NOT a datetime format. Datetime variables are numbers, not characters. To convert from your character represetation to a SAS datetime, use ANYDTDTM. informat, as follows:

data test;

input Date &:$21.;

realDatetime = input(date, anydtdtm.);

format realDateTime datetime21.;

datalines;

2002-01-10 00:00:00.0

2002-03-15 00:00:00.0

2002-04-23 00:00:00.0

;

proc print; run;

PG

PG
Orsini
Fluorite | Level 6

data have;                                        

   attrib                                          

     newdate length=8 format=mmddyy10.             

   ;                                               

   infile datalines4;                              

   input charvar $21.;                             

   newdate = input(scan(charvar,1," "),yymmdd10.); 

   put _all_;                                      

   datalines4;                                     

2002-01-10 00:00:00.0                              

2002-03-15 00:00:00.0                              

2002-04-23 00:00:00.0                              

;;;;                                               

run;                                             

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 4 replies
  • 45563 views
  • 0 likes
  • 4 in conversation