Search code examples
sasanovaletter

Variables missing SAS error code when using letters to denote treatment in ANOVA


I have been having this problem with SAS all year and I can fix it, but it ends up being time-consuming.

Example: When I use the code attached (a simple ANOVA code) I get errors that say I have invalid data for the treatment code. This seems to be because I have denoted the different treatments using A, B, C, D, and E. I can fix this by switching the letters to numbers but I feel like it should be able to run with the letters.

The specific error is: ERROR: One or more variables are missing or freq or weight is zero on every observation

SAS Code

The code I am using (pictured with proper format in picture) is: Data ANOVA3; input treat val; cards; C 96 B 69 D 65 E 34 A 89 C 90 D 74 E 49 B 58 D 41 C 60 A 90 A 106 B 95 E 41 D 54 C 57 A 99 D 35 E 18 C 62 B 78 B 96 E 24 A 71 ; run; title "problem3"; proc glm; class treat; model val= treat; lsmeans treat / stderr pdiff; run;

If anyone could please tell me how to run code without changing every data point into a number that would be great. This also seems to happen to me (only sometimes!) with M and F for male and female, but it used to work so I know I must be forgetting something.

Thanks


Solution

  • If you look at the SAS log, you should see a lot of errors from the DATA step that reads in the data. When you read in a character value, you need to use an informat to tell SAS that you are reading a character value, not a numeric value.

    Below I use the $1 informat:

    Data ANOVA3; 
    input treat $1. val; 
    cards; 
    C 96 
    B 69
    D 65
    ;
    
    * Check data;
    proc print data=ANOVA3;
    run;
    

    By the way, to format code you can paste it in then highlight the code, and click the {} button on the text formatting menu. It makes the code readable, separate from text. Or manually, you can place four spaces at the front of a line. The HELP for formatting text is: https://stackoverflow.com/help/formatting