BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mahi2pal
Calcite | Level 5
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? 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  Providing a format seems to take care of the issue for me:

use_format.png

 

Hope this helps,

 

cynthia

View solution in original post

5 REPLIES 5
data_null__
Jade | Level 19

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

Cynthia_sas
SAS Super FREQ

Hi:

  Providing a format seems to take care of the issue for me:

use_format.png

 

Hope this helps,

 

cynthia

mahi2pal
Calcite | Level 5
Where do give the format?
Cynthia_sas
SAS Super FREQ
It is highlighted in yellow in the screen shot in my previous posting.
Cynthia
Tom
Super User Tom
Super User

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

 

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2474 views
  • 1 like
  • 4 in conversation