BookmarkSubscribeRSS Feed
Munzhedzi
Calcite | Level 5

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.

5 REPLIES 5
LinusH
Tourmaline | Level 20

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
Bour9
Fluorite | Level 6

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;

Tom
Super User Tom
Super User

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

anushakalyani
Calcite | Level 5

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.


              

Scott_Mitchell
Quartz | Level 8

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 9998 views
  • 1 like
  • 6 in conversation