BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ursula
Pyrite | Level 9

Hi,

I did date format as mmddyy8. (01/01/16 -- with 2 digits year)  in SAS, but when I exported to csv file, the format of the date changed to 4 digits year, and it also showed 4 digits year when I opened the csv file with Notepad.

 

is there a way to keep the date format as mmddyy8. (with 2 digits year) when export to csv file?

 

for example:

Date in SAS = 01/01/16, when export to csv file, I want the date format same as the format in SAS -- 01/01/16 in csv file.

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ursula
Pyrite | Level 9

you are right.

when I run Proc contents, it showed the date has an "informat" as date9 and format as mmddyy8 at the same time.

so I removed the informat, and it works!

 

Thank you so much for your effort to help, I appreciate your time.

 

Have a great day and Happy New Year!

View solution in original post

8 REPLIES 8
ballardw
Super User

Please show the code you used to export to CSV. There are a number of different ways to create a CSV file and the solution to the format issue may change depending on your choice.

ursula
Pyrite | Level 9

I was using this code to export the file.

 

PROC EXPORT DATA=test DBMS=CSV
FILE='test.csv';run;

Reeza
Super User

I can't replicate your issue with SAS 9.3 and proc export. Make sure the format is applied to your dataset, you can confirm this with a proc contents on your data set. Does the following generate a file with the two digit years for you?

 

data test;
do i=1 to 12;
test_date=mdy(i, 20, 2016);
output;
end;
format test_date mmddyy8.;
run;

proc export data=test outfile='c:\_localdata\delete.csv' dbms=csv replace;
run;
ursula
Pyrite | Level 9

I run the code from you.

it showed 4 digits year if opened it in excel file.

But it showed 2 digets year when opened it in notepad, which is perfect!

 

For your review,

I used this format in my code.

PROC FORMAT;
VALUE test
-9="-9"
-1="-1"
0-HIGH=[MMDDYY8.];RUN;

 

data want;

set datahave;

format date test.;run;

 

PROC EXPORT DATA=want DBMS=CSV

  FILE= “want.csv”;

RUN;

 

But the date changed to 4 digits year. 

ursula
Pyrite | Level 9

I run the code from you.

it showed 4 digits year if opened it in excel file.

But it showed 2 digets year when opened it in notepad, which is perfect!

 

For your review,

I used this format in my code.

PROC FORMAT;
VALUE test
-9="-9"
-1="-1"
0-HIGH=[MMDDYY8.];RUN;

 

data want;

set datahave;

format date test.;run;

 

PROC EXPORT DATA=want DBMS=CSV

  FILE= “want.csv”;

RUN;

 

But the date changed to 4 digits year in csv file (open in ecxcel or notepad). 

Reeza
Super User

Post your log from that code please, as well as the output from a proc contents on your actual dataset. 

 

Proc contents data=want;

run;

 

 

Given that my code worked, its likely something incorrect in your process - one may be not having replace specified so that your new file isn't atually being created. Or the format isn't applied correctly to the want dataset.  

 

 

 

 

ursula
Pyrite | Level 9

you are right.

when I run Proc contents, it showed the date has an "informat" as date9 and format as mmddyy8 at the same time.

so I removed the informat, and it works!

 

Thank you so much for your effort to help, I appreciate your time.

 

Have a great day and Happy New Year!

Reeza
Super User
How are you exporting the data? When writing a CSV SAS honours formats applied usually, so you shouldn't have to change anything.

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
  • 8 replies
  • 9721 views
  • 3 likes
  • 3 in conversation