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

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
; 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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 
;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

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 
;
--
Paige Miller
Amir
PROC Star

Further to the solution provided by @PaigeMiller, more details can be found in the documentation, including for data that uses another separator for dates:

 

https://documentation.sas.com/?docsetId=ds2ref&docsetTarget=p1uyobuitxtzhwn10vu2ri4v0p00.htm&docsetV...

 

Kind regards,

Amir.

novinosrin
Tourmaline | Level 20

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 

Kurt_Bremser
Super User

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
;
Krissy217
Calcite | Level 5

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.;

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 5 replies
  • 5997 views
  • 1 like
  • 6 in conversation