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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.