Create a new variable based on the first non missing value from a list of variables


/ Published in: SAS
Save to your folder(s)



Copy this code and paste it in your HTML
  1. options missing='';
  2. Data mydata;
  3. input ID v1 v2 v3 v4;
  4. combvar=input(substr(cats(v1,v2,v3,v4),1,1),best.);
  5. datalines;
  6. 15 0 . 1 0
  7. 16 1 0 0 0
  8. 17 0 1 0 0
  9. 18 . . 0 0
  10. ;
  11. run;
  12.  
  13. proc print; run;
  14. ID v1 v2 v3 v4 combvar
  15. 15 0 . 1 0 0
  16. 16 1 0 0 0 1
  17. 17 0 1 0 0 0
  18. 18 . 0 0 0 0

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.