SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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