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

how to change values of a column in sas dataset

我的数据集是这样的

我想将所有 'Within the next 6 months' 更改为“< 6 个月” 同样,所有 'Between 6 months and a year' 到“6 到 12 个月”

我们该怎么做?

您可以尝试使用以下示例中的 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;

您可以执行以下操作并加载您需要更改的 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 ;