Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Excel Date in SAS 1

Status
Not open for further replies.

Forester83

Technical User
Aug 13, 2008
3
CA
In my excel spreadsheet I have a column titled date with the date format DD-MMM-YY (e.g., 20-May-08). When I import this file and look at it with proc print the format is DDMMMYYYY:HH:MM:SS (e.g., 20MAY2008:00:00:00). How can I format the date back to DD-MMM-YY? I know it may be a simple question but I am learning SAS day by day so I appreciate the help.

Cheers,

Mark
 
When SAS imports data from excel it converts the Excel date to SAS Datetime format. This is the number of seconds from jan 1 1960. If you want to display the data as dd-mmm-yy, you first need to convert this back to SAS date format. This is the number of days from jan 1 1960. I use the DATEPART() function along with a date format.

Code:
data x;
  x = datetime();
  put x=;
  y = datepart(x);
  put y=;
format y date8.;
run;

Take the last format statement off and you will see that 'y' is really the number of days from jan 1 1960.

I couldn't find any format that displays the date value with '-' so I made my own. This ends up as a string.

Code:
z = put(y, day2.)||'-'||put(y,monname3.)||'-'||put(y,year4.);

Hope this helps ya have a great weekend.
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top