BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
orlyz2k
Fluorite | Level 6

Hi, I was trying to format a table in proc tabulate. However part of the table didn't show the complete format I wrote in the proc format,

proc format;
value $dosegroupl (notsorted)
'0.003' = '0.003 mg/kg'
'0.03' = '0.03  mg/kg'
'0.3' = '0.3 mg/kg'
'2.5' = '2.5 mg/kg'
'5.0' = '5.0 mg/kg'
'10.0' = '10.0 mg/kg'
'15.0' = '15.0 mg/kg';
run;

proc tabulate data=bor missing;
format exdosa1 $dosegroupl. bor $resl.;
class mhdiag / order=freq;
class exdosa1 bor / preloadfmt order=data; * preloadfmt forces the specific ordering defined in proc format;

The result display as this:

微信图片_20220126202559.png

Not sure what's the problem is.

Can anyone help me? Many thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

It would help to explicitly describe which values are not displaying correctly.

 

However the values you show in the column heading for Exdosa1 shows that you have values in the data that do not have rules in the format. Clearest example is the multiple appearance of 10 and 15. Which very likely means that you have different values in the data that appear in the table as the same. If the actual value is "10" you did not provide a rule for display so would be shown as 10. If the value is " 10", same no rule plus if that leading "space" is some other non-printable character means the value is different than "10" so gets its own column.

 

An example: The third row of data has a null character, ASCII 255, not a space.

data example;
 input x $5.;
datalines;
10.0
10
 10
;

proc format;
value $dosegroupl (notsorted)
'0.003' = '0.003 mg/kg'
'0.03' = '0.03  mg/kg'
'0.3' = '0.3 mg/kg'
'2.5' = '2.5 mg/kg'
'5.0' = '5.0 mg/kg'
'10.0' = '10.0 mg/kg'
'15.0' = '15.0 mg/kg';
run;

proc tabulate data=example;
   class x;
   format x $dosegroupl.;
   table n,x;
run;

I think that you may also want the PRINTMISS option in the table options .

View solution in original post

5 REPLIES 5
orlyz2k
Fluorite | Level 6

Sorry the webpage auto removed part of the code. 

微信图片_20220126204250.png

BrunoMueller
SAS Super FREQ

Providing proc contents output of the data set bor would certainly help.

 

I created some test data and everything is just printed fine, see code below. There might be issues with length or type of variables.

 

proc format;
  value $dosegroupl (notsorted)
    '0.003' = '0.003 mg/kg'
    '0.03' = '0.03  mg/kg'
    '0.3' = '0.3 mg/kg'
    '2.5' = '2.5 mg/kg'
    '5.0' = '5.0 mg/kg'
    '10.0' = '10.0 mg/kg'
    '15.0' = '15.0 mg/kg'
  ;
run;

data bor;
  infile cards dlm=",";
  input
    mhdiag : $32.
  ;
  length exdosa1 $ 8;

  do exdosa1 = '0.003','0.03','0.3', '2.5', '5.0', '10.0','15.0';   
    output;
  end;

  cards;
BOR
PR (confirmed)
unconfirmed PR
;

proc tabulate data=bor missing;
  format exdosa1 $dosegroupl.;
  class mhdiag / order=freq;
  class exdosa1 / preloadfmt order=data;

  * preloadfmt forces the specific ordering defined in proc format;
  table mhdiag, exdosa1;
run;
orlyz2k
Fluorite | Level 6
Thank you Bruno!I finally figured that it’s because there are 5 and 5.0 in my exdosa1 variable and so like the other ones didn’t display right. The tip is really helpful! Thanks a lot!
ballardw
Super User

It would help to explicitly describe which values are not displaying correctly.

 

However the values you show in the column heading for Exdosa1 shows that you have values in the data that do not have rules in the format. Clearest example is the multiple appearance of 10 and 15. Which very likely means that you have different values in the data that appear in the table as the same. If the actual value is "10" you did not provide a rule for display so would be shown as 10. If the value is " 10", same no rule plus if that leading "space" is some other non-printable character means the value is different than "10" so gets its own column.

 

An example: The third row of data has a null character, ASCII 255, not a space.

data example;
 input x $5.;
datalines;
10.0
10
 10
;

proc format;
value $dosegroupl (notsorted)
'0.003' = '0.003 mg/kg'
'0.03' = '0.03  mg/kg'
'0.3' = '0.3 mg/kg'
'2.5' = '2.5 mg/kg'
'5.0' = '5.0 mg/kg'
'10.0' = '10.0 mg/kg'
'15.0' = '15.0 mg/kg';
run;

proc tabulate data=example;
   class x;
   format x $dosegroupl.;
   table n,x;
run;

I think that you may also want the PRINTMISS option in the table options .

orlyz2k
Fluorite | Level 6
Hi Ballardw, Yeah i did find out it’s because of the different format of 5.0 and 5. I add the rule to proc format and the problem solved! Thanks a lot!

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
  • 5 replies
  • 653 views
  • 2 likes
  • 3 in conversation