sas - How to split one variable into multiple rows -


**application_id                reaon_code            value**  123                              ab31ab45                £500 124                              ab43rd49ty87            £640 125                              rt87                    £900 126                              cd19rv29               £1000 

what want separate reason_code variable taking subset of this, each reason has 4 character , combine 2 letters , 2 numbers,

the dataset want following:

application_id             reason_code                       value  123                             ab31                          £500  123                             ab45                          £500 124                             ab43                          £640 124                             rd49                          £640 124                             ty87                          £640 145                             rt87                          £900 

hope make sense.

2nd question, want create flag showing:

application_id             reason_code               value           waterfall_reason                                                           unique_reason 123                             ab31                          £500                       1 (as ab31 first)                              0 (as hits both ab31 , ab45) 123                             ab45                          £500                       0 (as hits ab31 first)                             0 (as hits both ab31 , ab45) 124                             ab43                         £640                        1 (as hits ab43 first)                             0 (as hits both ab43,rd49 , ty87) 124                             rd49                         £640                        0                                                            0 124                            ty87                           £640                        0                                                            0 145                            rt87                          £900                        1 (as hits rt87 first)                              1 (as hit rt87)  

 data have;  informat application_id   $3.              reaon_code $100.           value nlmnlgbp.;  input application_id                reaon_code            value;  format value nlmnlgbp.; cards;  123                              ab31ab45                £500 124                              ab43rd49ty87            £640 125                              rt87                    £900 126                              cd19rv29               £1000  ;  data want;  format application_id   $3.              reason_code $4.           value     nlmnlgbp.;  set have;  origcode = reaon_code;  keep application_id   reason_code   value ;  start = 1 25 4;* arbitrary high number;* use while or until, also.;      reason_code = substr( reaon_code , start ,   4 ) ;      if reason_code = '' leave;       output;   end;   run; 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -