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

 

Hi all,

 

Is there a SAS format to make the date appearing as shown below:

 

04-Sep-2017

14-Jun-2015

21-May-2016

 

Thanks

zimcom

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Try

date11.;


data test;
input date :date11.;
format date date11.;
cards;
04-Sep-2017
14-Jun-2015
21-May-2016
;

 

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

Try

date11.;


data test;
input date :date11.;
format date date11.;
cards;
04-Sep-2017
14-Jun-2015
21-May-2016
;

 

zimcom
Pyrite | Level 9
THANK YOU !!
Have a great weekend!
Jagadishkatam
Amethyst | Level 16

I checked but not sure if there is any such format, but if you need the date in that format probably you can try the below code with prxchange function which generates a character variable of date in the expected format.

 

data have;
input date:date10.;
new=prxchange('s/(\d{1,2})(\w{3})(\d{4})/$1-$2-$3/',-1,strip(put(date,date9.)));
format date date9.;
cards;
04-Sep-2017
14-Jun-2015
21-May-2016
;

 

 

Thanks,
Jag
zimcom
Pyrite | Level 9
date11.;

works perfect!

 

Thank you! 

Jagadishkatam
Amethyst | Level 16
Its interesting, I never used it.
Thanks to @novinosrin now i know when to use it.
Thanks,
Jag
ballardw
Super User

@Jagadishkatam wrote:

I checked but not sure if there is any such format, but if you need the date in that format probably you can try the below code with prxchange function which generates a character variable of date in the expected format.

 

data have;
input date:date10.;
new=prxchange('s/(\d{1,2})(\w{3})(\d{4})/$1-$2-$3/',-1,strip(put(date,date9.)));
format date date9.;
cards;
04-Sep-2017
14-Jun-2015
21-May-2016
;

 

 


This looks like a case of using a tool one is more familiar with. Proc Format has a lot of options for making custom formats if one such as Date11 didn't work. Consider if the OP had wanted @ characters instead of dashes [admittedly not a likely need but to illustrate]:

proc format library=work;
Picture mydatefmt (default=11)
  low-high= '%0d@%b@%Y' (datatype=date);
run;

data _null_;
   x='23JAN2019'd;
   put x= mydatefmt.;
run;

So with the available format we don't have to modify the data set, just use the new format for the procedure output.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 748 views
  • 4 likes
  • 4 in conversation