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 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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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