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.
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;
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;
Thanks a lot! that worked for me. A
$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
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.