Hi SAS Forum;
I have the following dataset.
data have;
input ID status0 $ 5-11 status1 $ 13-19 status2 $ 21-27 status3 $ 29-35 status4 $ 37-43;
cards;
111 current current current current current
222 npna dwo dwo 1-30 90+
333 current dwo 31-60 61-90 dwo
;
run;
What I wanted:
I wanted to force this condition for each and every observation.
Condition is: if an account hits "dwo" state at any point from status0 to status4, then the remainder of the statuses also should be "dwo"
Answer:
ID | status0 | status1 | status2 | status3 | status4 |
111 | current | current | current | current | current |
222 | npna | dwo | dwo | dwo | dwo |
333 | current | dwo | dwo | dwo | dwo |
My code below does do the job correctly, but could any expert suggest me an alternative elagont code (my original dataset has 24 statuses such as status0, status1, ......status24 which neccesitate me to write a long code if I use my long coding appraoch below).
.
data want2;
set have;
if status0 in ("dwo") then do;
status1= "dwo";
status2= "dwo";
status3= "dwo";
status4= "dwo";
end;
if status1 in ("dwo") then do;
status2= "dwo";
status3= "dwo";
status4= "dwo";
end;
if status2 in ("dwo") then do;
status3= "dwo";
status4= "dwo";
end;
if status3 in ("dwo") then do;
status4= "dwo";
end;
run;
Thanks
Mirisa
Mirisa,
In general, when you have a set of variables that should be processed in very similar fashion, arrays are often a good tool for the job. Here's how the program might look:
data want;
set have;
array all5 {5} status0-status4;
do i=2 to 5;
if all5{i-1} = "dwo" then all5{i}="dwo";
end;
run;
It should be easy to expand this to 25 variables instead of 5.
Good luck.
Mirisa,
In general, when you have a set of variables that should be processed in very similar fashion, arrays are often a good tool for the job. Here's how the program might look:
data want;
set have;
array all5 {5} status0-status4;
do i=2 to 5;
if all5{i-1} = "dwo" then all5{i}="dwo";
end;
run;
It should be easy to expand this to 25 variables instead of 5.
Good luck.
Hi Astounding,
Thank you very much for your code. It worked well.
Regards
Mirisa
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.