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;                                             

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 44251 views
  • 0 likes
  • 4 in conversation