Hi,
I have data delimited with a comma, where dates are formatted in 23/06/2020 format. I want to add them to a sas table. Below is an example, could you please guide how should I do it to have the column 'date' formatted as date? it can be either ddmmyys10. or date9.
DATA want;
LENGTH character $60. ;
INFILE DATALINES DLM=',';
INPUT character $ date ddmmyys10.;
DATALINES;
aaa,20/06/2020
b bb,21/06/2020
cc c,22/06/2020
;
RUN;
Please try the below code
We need to use the colon to read the dates with an informat ddmmyy10. and display the date with format date9.
DATA want;
LENGTH character $60. ;
INFILE DATALINES DLM=',';
INPUT character$ date:ddmmyy10.;
format date date9.;
DATALINES;
aaa,20/06/2020
b bb,21/06/2020
cc c,22/06/2020
;
RUN;
Please try the below code
We need to use the colon to read the dates with an informat ddmmyy10. and display the date with format date9.
DATA want;
LENGTH character $60. ;
INFILE DATALINES DLM=',';
INPUT character$ date:ddmmyy10.;
format date date9.;
DATALINES;
aaa,20/06/2020
b bb,21/06/2020
cc c,22/06/2020
;
RUN;
@Jagadishkatam @Kurt_Bremser @andreas_lds Thanks for fast response, it's working now 🙂
You could use the informat-statement to assign the proper informat to the variable date prior to the input-statement:
DATA want;
LENGTH character $60. date 8;
informat date ddmmyys10.;
format date date9.;
INFILE DATALINES DLM=',';
INPUT character $ date;
DATALINES;
aaa,20/06/2020
b bb,21/06/2020
cc c,22/06/2020
;
RUN;
Also note that it is highly recommended to assign a date-format to variables containing date-values.
data want;
infile datalines dlm=',' dsd;
input character :$60. date :ddmmyy10.;
format date ddmmyy10.;
datalines;
aaa,20/06/2020
b bb,21/06/2020
cc c,22/06/2020
;
By using the colon modifier, you can set the length of the variables through the informat in the INPUT statement.
Add the DSD option to correctly deal with two consecutive delimiters (missing values).
A data step with DATALINES needs no RUN, as the DATALINES statement and the datalines block constitute the step boundary.
Edit: removed the unnecessary LENGTH statement.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.