Format Date to DD-MMM-YY

Reply
New Contributor
Posts: 2

Format Date to DD-MMM-YY

Hi ,

I want to format the date from Date 9 to DD-MMM-YY.Example  20DEC1984 to 20-DEC-84.

I also want to export file from SAS to CSV and when i open the file using notepad the data should be seperated by comma,.

Examples attached.

Attachment
Attachment
Super User
Posts: 5,424

Re: Format Date to DD-MMM-YY

Posted in reply to Munzhedzi

a) Funny, I thought there would be format for this, but none that matches your requirement. Do you really need the years without the century part? You could either build a new date format, which could be a bit complex if you are a novice. Or you cold store the date in a char column (the result of put(date,date11.) and some string manipulation.

b) PROC EXPORT....?

Data never sleeps
New Contributor
Posts: 3

Re: Format Date to DD-MMM-YY

Posted in reply to Munzhedzi

You can create your own format :

proc format;

picture DTJMHM

  other= '%0d-%B-%Y' (datatype=date);

run;

proc export dbms=csv data=sashelp.air outfile='\\anywhere\YourFile.csv';

run;

Super User
Super User
Posts: 7,039

Re: Format Date to DD-MMM-YY

Need to use lowercase B and Y in the PICTURE format to get the 3 char month and 2 digit year.

New Contributor
Posts: 3

Re: Format Date to DD-MMM-YY

Posted in reply to Munzhedzi

if date_9 =20DEC1984

would like convert as 20-DEC-84

You may use date_format= substr(date_9,1,2)||'-'||substr(date_9,3,3)||'-'||substr(date_9,6,4) and use format     

                   Format date_format DDMMYYD9.


              

Super Contributor
Posts: 297

Re: Format Date to DD-MMM-YY

Posted in reply to Munzhedzi

PROC FORMAT;

PICTURE DDMMMYYD

  LOW - HIGH = '%0d-%b-%y' (DATATYPE=DATE);

RUN;

DATA HAVE;

INFILE DATALINES DLM=",";

INPUT DATES ;

INFORMAT DATES DATE9.;

FORMAT DATES DATE9.;

DATALINES;

01JUL2013

01AUG2013

01SEP2013

01NOV2013

01DEC2013

01JAN2014

;

RUN;

DATA WANT;

%LET _EFIERR_ = 0;

%LET _EFIREC_ = 0;

  FILE "E:\WANT.CSV" DSD DLM=",";

  IF _N_ = 1 THEN DO;

  PUT "DATES" "," "OBS";

  END;

  SET HAVE;

  OBS+1;

  FORMAT DATES DDMMMYYD.;

  PUT DATES @;

  PUT OBS;

  IF _ERROR_ THEN CALL SYMPUTX('_EFIERR_',1);

  IF EFIEOD THEN CALL SYMPUTX('_EFIREC_',EFIOUT);

RUN;

Ask a Question
Discussion stats
  • 5 replies
  • 2522 views
  • 1 like
  • 6 in conversation