- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Jagadishkatam @Kurt_Bremser @andreas_lds Thanks for fast response, it's working now 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.