BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cactooos
Obsidian | Level 7

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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;

 

 

 

Thanks,
Jag

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

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;

 

 

 

Thanks,
Jag
cactooos
Obsidian | Level 7

@Jagadishkatam @Kurt_Bremser @andreas_lds Thanks for fast response, it's working now 🙂

andreas_lds
Jade | Level 19

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.

Kurt_Bremser
Super User
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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 2630 views
  • 3 likes
  • 4 in conversation