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;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.