Hi,
I have problem with date variable. I want to have format DD/MM/YYYY.
This is my code which doesn't work (date format is BEST12.):
DATA xxx;
INPUT quantity date DDMMYY10. id;
DATALINES;
59 01/01/2009 3
59 01/02/2009 2
59 01/03/2009 1
;
Use the proper format, DDMMYYS10.
DATA xxx;
infile cards missover;
INPUT quantity date DDMMYY10.;
format date ddmmyys10.;
DATALINES;
59 01/01/2009
59 01/02/2009
59 01/03/2009
;
Use the proper format, DDMMYYS10.
DATA xxx;
infile cards missover;
INPUT quantity date DDMMYY10.;
format date ddmmyys10.;
DATALINES;
59 01/01/2009
59 01/02/2009
59 01/03/2009
;
Further to the solution provided by @PaigeMiller, more details can be found in the documentation, including for data that uses another separator for dates:
Kind regards,
Amir.
Hi @ab97_cd Your code works fine. An addition of a format statement to display SAS dates makes it convenient for reading ease.
DATA xxx;
INPUT quantity date DDMMYY10. id;
format date ddmmyy10.;
DATALINES;
59 01/01/2009 3
59 01/02/2009 2
59 01/03/2009 1
;
proc print noobs;run;
quantity date id
59 01/01/2009 3
59 01/02/2009 2
59 01/03/2009 1
Use the colon modifier, or the format will override the delimiters.
Also assign a date display format when using an informat:
data xxx;
input quantity date :DDMMYY10. id;
format date ddmmyy10.;
datalines;
59 01/01/2009 3
59 01/02/2009 2
59 01/03/2009 1
;
The ddmmyy informat accepts all kinds of separators: colons, dashes, slashes, underlines, periods:
data test;
input date :ddmmyy10.;
format date yymmddd10.;
datalines;
27.11.2019
27/11/2019
27-11-2019
27_11_2019
27:11:2019
;
You will need to use the DDMMYYS10. format. This tells SAS you want to have 10 characters (including the slashes) in your date and the "S" says to use slashes in the format.
You will need a format statement before the datelines statement that looks like:
Format date DDMMYYS10.;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.