data Abun_dw20d_summary ; informat bins $30.; format bins $30.; length bins $30.;
input bins $ CM1DW20D CM3DW20D CW1DW20D ODWD W1DW4D;
datalines;
Acinetobacter 2477.123456789 195 163 45 77
Actinoalloteichus 2431 220 198 69.123456789 6774
Bacillus 2456 173 155 78 785
Bletilla 2412 135 116.123456789 45 123;
run;
proc transpose data=Abun_dw20d_summary out=bint;
var _all_;
by bins;
run;
My decimals are getting truncated in output dataset, can anyone help me on this?
Hi:
Providing a format seems to take care of the issue for me:
Hope this helps,
cynthia
@mahi2pal wrote:data Abun_dw20d_summary ; informat bins $30.; format bins $30.; length bins $30.; input bins $ CM1DW20D CM3DW20D CW1DW20D ODWD W1DW4D; datalines; Acinetobacter 2477.123456789 195 163 45 77 Actinoalloteichus 2431 220 198 69.123456789 6774 Bacillus 2456 173 155 78 785 Bletilla 2412 135 116.123456789 45 123; run; proc transpose data=Abun_dw20d_summary out=bint; var _all_; by bins; run;
My decimals are getting truncated in output dataset, can anyone help me on this?
Did you notice this?
NOTE: Numeric variables in the input data set will be converted to character in the output data set.
SAS used a default format I think BEST12.
If you want more decimal places use a different format.
Hi:
Providing a format seems to take care of the issue for me:
Hope this helps,
cynthia
1) Don't include the character variables in the VAR statement and PROC TRANSPOSE will not convert your numeric variables to character.
2) If you must include the character variables then attach a format to the numeric variables that is long enough.
Example:
data have ;
length bins $30.;
input bins CM1DW20D CM3DW20D ;
datalines;
Acinetobacter 2477.123456789 195
Bletilla 2412 116.123456789
;
proc print width=min; title 'HAVE';
format _numeric_ best32.;
run;
proc transpose data=have out=want1;
by bins;
run;
proc print width=min; title 'WANT1';
format _numeric_ best32.;
run;
proc transpse data=have out=want2;
by bins;
var _all_;
format _numeric_ best32.;
run;
proc print width=min; title 'WANT2';
run;
title;
HAVE Obs bins CM1DW20D CM3DW20D 1 Acinetobacter 2477.123456789 195 2 Bletilla 2412 116.123456789 WANT1 Obs bins _NAME_ COL1 1 Acinetobacter CM1DW20D 2477.123456789 2 Acinetobacter CM3DW20D 195 3 Bletilla CM1DW20D 2412 4 Bletilla CM3DW20D 116.123456789 WANT2 Obs bins _NAME_ COL1 1 Acinetobacter bins Acinetobacter 2 Acinetobacter CM1DW20D 2477.123456789 3 Acinetobacter CM3DW20D 195 4 Bletilla bins Bletilla 5 Bletilla CM1DW20D 2412 6 Bletilla CM3DW20D 116.123456789
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.