SAS 中重复字段 --- 使用 RETAIN 语句?
我正在尝试执行以下操作。
我想要这个:
ID Antibiotic1 Antibiotic2
1 1 .
1. .
1. 2 1. 。 2. 1 2 3 . 2. 。 3 1 .
3. 2
变成这样:
ID Antibiotic1 Antibiotic2
1 1 2
1 1 2
1 1 2 1 1 2 2 3 1 2 3 1 2 3 1 3 1 1
3 2 2
有什么想法吗?
谢谢你!!
I am trying to do the following.
I want this:
ID Antibiotic1 Antibiotic2
1 1 .
1 . .
1 . 2
1 . .
2 . 1
2 3 .
2 . .
3 1 .
3 . 2
To turn into this:
ID Antibiotic1 Antibiotic2
1 1 2
1 1 2
1 1 2
1 1 2
2 3 1
2 3 1
2 3 1
3 1 1
3 2 2
Any ideas?
THANK YOU!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你正在寻找这样的东西。请注意,下面我将默认抗生素值初始化为 55,只是为了让它脱颖而出,但对于上面给出的示例,您可能希望将其更改为 2。
输出是:
I think you're looking for something like this. Note that below I initialized the default antibiotic values to 55 just so it stood out, but you probably want to change this to 2 for the example you gave above.
The output is:
看起来您只是根据您在数据集中观察到的因素随机估算缺失值。一个问题可能是考虑您是否希望这些插补取决于它们在数据集中出现的频率。例如,如果非缺失数据中有 80% 为 1,那么您是否希望在缺失数据中以 0.8 的概率生成 1?
您可能需要阅读 PROC SURVEYSELECT ,这对于模拟从观察到的数据样本中进行抽取很有帮助。可能需要首先使用 PROC TRANSPOSE 将数据集转置为固定宽度的数据框,以便它是一个长数据集而不是宽数据集。那么您将只有一列缺少数据。
It looks like you're just randomly imputing the missing values based on factors you observed in the dataset. A wrinkle might be to consider whether you want these imputations to depend on the frequency in which they occur in the dataset. For instance, if you have 80% 1s in the non-missing data, do you want to generate 1 with probability 0.8 in the missing data?
You might want to read up on PROC SURVEYSELECT which is good for simulating draws from the sample of observed data. It may be necessary to transpose the dataset into a fixed width data frame first using PROC TRANSPOSE so that it's a long dataset and not a wide one. Then you will have only one column with missing data.