在使用字母表示ANOVA中的处理时,出现了SAS错误代码”Variables missing”。

huangapple go评论83阅读模式
英文:

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

问题

我整年都遇到SAS的这个问题,我可以修复它,但最终会耗费很多时间。

示例:当我使用附加的代码(一个简单的ANOVA代码)时,我会收到错误消息,说我的治疗代码有无效数据。这似乎是因为我用A、B、C、D和E表示不同的治疗方法。我可以通过将字母更改为数字来解决此问题,但我觉得应该能够使用字母运行。

具体错误是:ERROR: One or more variables are missing or freq or weight is zero on every observation

SAS 代码

我正在使用的代码(以图片中的正确格式显示)是: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;

如果有人能告诉我如何在不将每个数据点更改为数字的情况下运行代码,那将是非常好的。这在我身上也发生过(只是有时候!),例如,对于男性和女性的M和F,但以前可以工作,所以我知道我一定忘了某些东西。

谢谢。

英文:

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

答案1

得分: 0

如果您查看SAS日志,您应该会看到来自读取数据的DATA步骤的许多错误。当您读取字符值时,需要使用一个格式来告诉SAS您正在读取字符值,而不是数值值。

以下是我使用的$1格式:

Data ANOVA3; 
input treat $1. val; 
cards; 
C 96 
B 69
D 65
;

* 检查数据;
proc print data=ANOVA3;
run;

顺便说一下,要格式化代码,您可以粘贴代码,然后将代码部分突出显示,然后单击文本格式化菜单上的{}按钮。这可以使代码更易读,并与文本分开。或者您可以手动在行的开头放置四个空格。有关文本格式化的帮助信息,请参阅:https://stackoverflow.com/help/formatting

英文:

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

答案2

得分: 0

A, B, C, D 和 E 不是有效的数值。但是如果你在 MISSING 语句中包含了这些字母,那么它们将被视为特殊缺失值的有效表示。.A, .B, .C, .D 和 .E。

如果你想让 TREAT 成为一个字符变量,在 INPUT 语句之前要先定义它。

data ANOVA3;
   length treat $1 val 8 ;
   input treat val;

或者在 INPUT 语句中使用字符格式,这样 SAS 将更改对你想要的变量类型的猜测。

确保包括 : 修饰符,这样输入语句仍然会读取下一行中的下一个值,而不是固定数量的字节。

data ANOVA3;
   input treat :$1. val;
英文:

A, B, C, D and E and not valid numeric values. But if you have included those letters in the MISSING statement then they will be read as valid representations of the special missing values .A, .B, .C, .D and .E .

If you want TREAT to be a character variable either DEFINE it before the INPUT statement.

data ANOVA3;
   length treat $1 val 8 ;
   input treat val;

Or use a CHARACTER informat with it in the INPUT statement so that SAS will change its GUESS of the type of variable you wanted.

Make sure to include the : modifier so the input statement still reads the next value on the line instead of a fixed number of bytes.

data ANOVA3;
   input treat :$1. val;

huangapple
  • 本文由 发表于 2023年6月16日 06:37:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76485908.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定