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

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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