最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sas - Move values of a variable where not missing the value of another one - Stack Overflow

programmeradmin0浏览0评论

suppose to have the following:

data have;
  input ID :$20. Admission :date09. Discharge :date09. All  Variable1 Variable2; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 2.45  3.5    .
0001 21FEB2015 31DEC2015   .    .    2.3
0002 01JAN2015 31DEC2015 2.00  7.5    .
0002 14FEB2020 21FEB2020   .    .    1.0
;

Is there a way to get the following?

data want;
  input ID :$20. Admission :date09. Discharge :date09. All  Variable1 Variable2; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 2.45  3.5   2.3
0001 21FEB2015 31DEC2015   .    .     .
0002 01JAN2015 31DEC2015 2.00  7.5   1.0
0002 14FEB2020 21FEB2020   .    .     .
;

In other words if and where it happens I would like to move the value of Variable2 where not missing(All).

Thank you in advance

suppose to have the following:

data have;
  input ID :$20. Admission :date09. Discharge :date09. All  Variable1 Variable2; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 2.45  3.5    .
0001 21FEB2015 31DEC2015   .    .    2.3
0002 01JAN2015 31DEC2015 2.00  7.5    .
0002 14FEB2020 21FEB2020   .    .    1.0
;

Is there a way to get the following?

data want;
  input ID :$20. Admission :date09. Discharge :date09. All  Variable1 Variable2; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 2.45  3.5   2.3
0001 21FEB2015 31DEC2015   .    .     .
0002 01JAN2015 31DEC2015 2.00  7.5   1.0
0002 14FEB2020 21FEB2020   .    .     .
;

In other words if and where it happens I would like to move the value of Variable2 where not missing(All).

Thank you in advance

Share Improve this question asked Feb 5 at 20:35 NewUsr_statNewUsr_stat 2,5835 gold badges29 silver badges41 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

You can do a self-update statement by ID and then set the Variable1-Variable2 to missing when all is missing.

data want;
    update have
           have
    ;
    by id;

    if(all = .) then call missing(Variable1, Variable2);
run;
ID      Admission   Discharge   All    Variable1   Variable2
0001    21FEB2015   31DEC2015   2.45   3.5         2.3
0001    21FEB2015   31DEC2015   .      .           .  
0002    14FEB2020   21FEB2020   2      7.5         1
0002    14FEB2020   21FEB2020   .      .           .

The update statement is similar to a merge but it handles missing values differently. To learn more about what the Update statement does, see SAS documentation on the UPDATE statement.

发布评论

评论列表(0)

  1. 暂无评论