SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to use ODS to export correct CSV format?

Reply
Super Contributor
Posts: 319

How to use ODS to export correct CSV format?

Hi, all:

 

I have a variable name "formatted_value",  I use ODS to export my SAS file into CSV format (Code shown below).  However, it changed the number form after export.  How to keep the oringinal format for "formatted_value"?  The "formatted_value" in SAS is Charateric.

 

Thanks.

 

ods csv file="\\Libraries\Documents\Final2020.CSV";

proc print data=yt.final;

run;

ods csv close;

 

For example,

SAS formatted_value

17.0

8.0

100.0

 

After ODS export,

CSV formatted_value

17

8

100

Super User
Super User
Posts: 7,988

Re: How to use ODS to export correct CSV format?

Hi,

 

Can I check, how are you opening the .csv file which is created?  Are you opening the file in Excel for example?  If so then therein lies your problem.  If you open the file in notepad you should see the data exactly as it is in the dataset, Excel has a lot of these "features" and its one of the top (of many) reason why not to use Excel.  

 

If however your data appears in Notepad without it, then please post a small datastep example of the data you have, to go along with the export, so we can test it.

Super User
Posts: 11,343

Re: How to use ODS to export correct CSV format?

1. Specify the format in the procedure generating output:

proc print data=yt.final;

   var myvariable;

   format myvariable f5.1;

run;

 

2. Do not use Excel to look at the result, it is IGNORING the trailing 0.

Open the set in an actual text program such as Notepad. CSV contains NO Format information in the file so the reading program picks the appearance.

 

Or use a method that specifies appearance to Excel which would work which means a different ODS destination and methods vary depending on destination chosen.

Super Contributor
Posts: 319

Re: How to use ODS to export correct CSV format?

I can't format the number, because I have other format shown below.

 

47989
680
31
681
187
5814
405
319
149
887
5100
4047
74
33
Super User
Posts: 11,343

Re: How to use ODS to export correct CSV format?


ybz12003 wrote:

I can't format the number, because I have other format shown below.

 

47989
680
31
681
187
5814
405
319
149
887
5100
4047
74
33

Comment does not make sense when you said in the original post:

"

For example,

SAS formatted_value

17.0

8.0

100.0

"

So which is it?

Ask a Question
Discussion stats
  • 4 replies
  • 338 views
  • 0 likes
  • 3 in conversation