BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

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

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ballardw
Super User

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.

ybz12003
Rhodochrosite | Level 12

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
ballardw
Super User

@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?

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1282 views
  • 0 likes
  • 3 in conversation