-1

I am very new to SAS and want to create a simple dummy variable (MALE) that equals 1 if SEX = 1, and equals 0 if SEX = 2. However, I get error messages: ERROR: The decimal specification of 2 must be less than the width specification of 1.

How do I solve this? This is the code I use:

DATA WORK.BMI_D ;
  SET WORK.BMI ;

  IF SEX = 1 THEN MALE = 1; 
    ELSE MALE = 0;
RUN;

The variable SEX has length 8, type Numeric and format F8.2. What am I doing wrong?

  • Did you try what is in [ERROR: The decimal specification of 15 must be less than the width specification of 15](https://communities.sas.com/t5/SAS-Programming/ERROR-The-decimal-specification-of-15-must-be-less-than-the/td-p/751759) ? – Kermit May 30 '22 at 12:17
  • The error must be for some other format as F8.2 does not have the decimal places (2) larger than the total width (8). Since you have a strange format attached to SEX (why include two decimal places or use 8 characters to display values of 1 or 2?) it is possible you have an invalid format attached to some other variable. – Tom May 30 '22 at 14:22
  • Include the log and error message. – Reeza May 30 '22 at 17:32

1 Answers1

0

You have not showed the code that is generating that error message but why not just remove the illogical format that you have attached to the variable SEX. Perhaps the error is from later step that is trying to display SEX with a width of only 1 byte and is having trouble display the strings like 1.00 or 2.00 that the F8.2 format would generate.

Since there is no need to use a special display format for numeric values of 1 and 2 just remove the format from SEX and see if that solves the issue.

DATA WORK.BMI_D ;
  SET WORK.BMI ;

  IF SEX = 1 THEN MALE = 1; 
  ELSE MALE = 0;

  format sex ;
RUN;
Tom
  • 47,574
  • 2
  • 16
  • 29