BookmarkSubscribeRSS Feed
ashoks321
Calcite | Level 5

Hello,

        I'm trying to export a SAS table as a CSV file using proc export. I'm not sure why the leading zeros is getting truncated in one of the columns.

I tried to use the ODS csv option and also tried to export as a .txt file but still losing the leading zeroes.

I'm looked up the forums and I'm not sure I was able to find any other solution that works for me.

 

Just FYI, the file gets imported to a tableau workbook and so the end user is not able to search the data values as it's not accurate.

There are few other values that are longer than these missing values and they appear accurate so I'm not sure if the length is an issue.

 

Any help is much appreciated!

 

This is the proc export code I used.

PROC EXPORT
DATA= Data_Feb2019
OUTFILE="\path\Feb 2019 results.csv"
DBMS = csv REPLACE;
RUN;

 

Hoping to hear soon!

Ashok

 

6 REPLIES 6
Tom
Super User Tom
Super User

You need to ask that question on a Tableau forum.  

SAS will not remove the leading zeros when it generates a CSV file.   From either a character variable or a numeric variable that is formatted to display them.

Example:

data test;
  do i=0,1,2,10,12 ;
    z=i;
    format z z2.;
    char=put(i,Z2.);
    output;
  end;
run;

data _null_;
  file log dsd ;
  set test;
  put (_all_) (+0);
run;
455   data _null_;
456     file log dsd ;
457     set test;
458     put (_all_) (+0);
459   run;

0,00,00
1,01,01
2,02,02
10,10,10
12,12,12
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

As Tom has shown you control the leading zeros using the .z

using @Tom code see how the zeros only pad the spaces in front of the numbers  If your output number is larger than the format for the value a decimal is included and the number is converted.

data test;
  do i=0,1,2,10,12,112,456,9876,123456789 ;
    z=i;
    format z z8.;
    char=put(i,Z8.);
    output;
  end;
run;

data _null_;
  file log dsd ;
  set test;
  put (_all_) (+0);
run;
0,00000000,00000000
1,00000001,00000001
2,00000002,00000002
10,00000010,00000010
12,00000012,00000012
112,00000112,00000112
456,00000456,00000456
9876,00009876,00009876
123456789,1.2346E8,1.2346E8
kiranv_
Rhodochrosite | Level 12

if you have  tableau desktop, you can directly connect to SAS.

ashoks321
Calcite | Level 5
Hi Tom, thanks for the reponse.
I did open the csv file and it seemed the zero truncated in that already. So I'm not totally sure it's a tableau issue.
I'll try the format changes you suggested.
Tom
Super User Tom
Super User

@ashoks321 wrote:
Hi Tom, thanks for the reponse.
I did open the csv file and it seemed the zero truncated in that already. So I'm not totally sure it's a tableau issue.
I'll try the format changes you suggested.

Then you probably opened the file with something else that doesn't understand it. Perhaps Excel? Open the file with a text editor.

filename csv temp;
PROC EXPORT
DATA= test
OUTFILE=csv
DBMS = csv REPLACE;
RUN;

data _null_;
 infile csv ;
 input;
 put _infile_;
run
i,z,char
0,01,00
1,01,01
2,01,02
10,01,10
12,01,12
Tom
Super User Tom
Super User

Just tell Tableau how to treat the field.

Tableau 10.5

image.png

 

image.png

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 3387 views
  • 0 likes
  • 4 in conversation