简体   繁体   English

如何在SAS中重新编码变量?

[英]How to recode variables in SAS?

I tried to recode the missing values but instead lost all my other variables within a dataset 我试图重新编码缺失值,但丢失了数据集中的所有其他变量


BEFORE: 之前:

在此输入图像描述


AFTER: 后:

        data work.newdataset;
        if (year =.) then year = 2000;
        run;

在此输入图像描述

You are missing the SET statement. 您缺少SET语句。

data want;
set have;
myvar=5;
run;

will create a new dataset, want , from have , with the new variable value applied (or the recode or whatever). 将创建一个新的数据集, want ,从have ,有(或重新编码或其他)应用的新的变量值。 You could also do 你也可以这样做

data have;
set have;
myvar=5;
run;

That would replace have with itself plus the recode/whatever. 这将取代have与自身加上重新编码/不管。 This is actually less common in SAS; 这在SAS中实际上并不常见; it is often preferable to do all recodes in one step, but to create a new dataset (so that the code is reversible easily). 通常最好一步完成所有重新编码,但要创建一个新的数据集(以便代码可以轻松地反转)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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