如何更改sas数据集中列的值

时间:2015-05-27 08:38:54

标签: sas

我的数据集是这样的 enter image description here

我想将所有'在未来6个月内'更改为'< 6个月' 同样地,所有“6个月到1年”到“6到12个月”

我们怎么能这样做?

2 个答案:

答案 0 :(得分:1)

您可以尝试使用tranwrd函数,如以下示例所示(请不要以最有效的方式编写):

data out1;
    set src;
    text = tranwrd(text, "Within the next 6 months", "< 6 Months");
    text = tranwrd(text, "Between 6 months and a year", "6 to 12 months");
run;

替代解决方案可能涉及使用格式:

proc format;
    value $sample_format
        "Within the next 6 months"="< 6 Months"
        "Between 6 months and a year"="6 to 12 months"
        ;
run;
data out2;
    set src;
    text = put(text, $sample_format.);
run;

答案 1 :(得分:1)

您可以执行以下操作,只需加载您需要更改的wait_time的任何其他值:

data input ;
  set input ;
  select (wait_time) ;
    when ('Within the next 6 months')    wait_time='<6 Months' ;
    when ('Between 6 months and a year') wait_time='6 to 12 Months' ;
    otherwise ;
  end ;
run ;