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.
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....?
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;
Need to use lowercase B and Y in the PICTURE format to get the 3 char month and 2 digit year.
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.
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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: