简体   繁体   中英

Error concerning decimal specification when creating a dummy variable in SAS

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM