Hello
What is the way to create data set "wanted2" using array instead of multiple IF else that written manually?
The row data contain information for each customer ID.
There is information about number of months that customer was expose to illness.
There is also follow up of 6 months with score 1-10.
IF customer touch score 11 then he died and then I need to give value 0 to indicator of exposition in the following months.
Data Rawdata;
Input ID No_Mon_expose Score1 Score2 Score3 Score4 Score5 Score6;
cards;
1 6 5 5 5 5 5 4
2 3 11 11 11 11 11 11
3 3 9 8 9 11 11 11
4 4 3 3 3 3 3 3
5 2 5 5 5 5 5 5
6 1 11 11 11 11 11 11
7 6 2 2 2 2 2 2
8 3 2 2 2 2 2 2
9 2 3 3 4 2 2 2
11 6 2 2 2 2 2 2
;
run;
data wanted1;
set Rawdata;
array Ind_Expose_Mon (6);
do i=1 to dim(Ind_Expose_Mon);
if i<=No_Mon_expose then Ind_Expose_Mon(i)=1;
else Ind_Expose_Mon(i)=0;
end;
drop i;
run;
Data wanted2;
Set wanted1;
IF Score1=11 then do;
Ind_Expose_Mon2=0;
Ind_Expose_Mon3=0;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else IF Score2=11 then do;
Ind_Expose_Mon3=0;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else IF Score3=11 then do;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else IF Score4=11 then do;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else IF Score5=11 then do;
Ind_Expose_Mon6=0;
end;
Run;
Hi @Ronein
I am a bit confused with your request:
Thank you for the clarifications.
Best,
For each customer there are 6 scores (in follow up period of 6 months).
However,For each customer there is a different number of months that he/she exposed.
So, in months after expose period the scores are not relevant (It is error information and we fix it in data set called "wanted1".
It was an error in row data ,so I am sending it again (6 scores for each ID)
Data Rawdata;
Input ID No_Mon_expose Score1 Score2 Score3 Score4 Score5 Score6;
cards;
1 6 5 5 5 5 5 4
2 3 11 11 11 11 11 11
3 3 9 8 9 11 11 11
4 4 3 3 3 3 3 3
5 2 5 5 5 5 5 5
6 1 11 11 11 11 11 11
7 6 2 2 2 2 2 2
8 3 2 2 2 2 2 2
9 2 3 3 4 2 2 2
11 6 2 2 2 2 2 2
;
run;
data wanted1;
set Rawdata;
array Ind_Expose_Mon (6);
do i=1 to dim(Ind_Expose_Mon);
if i<=No_Mon_expose then Ind_Expose_Mon(i)=1;
else Ind_Expose_Mon(i)=0;
end;
drop i;
run;
Data wanted2;
Set wanted1;
IF Score1=11 then do;
Ind_Expose_Mon2=0;
Ind_Expose_Mon3=0;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else IF Score2=11 then do;
Ind_Expose_Mon3=0;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else IF Score3=11 then do;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else IF Score4=11 then do;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else IF Score5=11 then do;
Ind_Expose_Mon6=0;
end;
Run;
Hi @Ronein
Thank you for the clarification.
Here is a way to automatize wanted1 -> wanted2:
data wanted2;
set wanted1;
array score (6);
array Ind_Expose_Mon (6);
do i=1 to dim(score);
if score(i)=11 then do;
do j = (i+1) to dim(Ind_Expose_Mon);
Ind_Expose_Mon(j)=0;
end;
end;
end;
drop i j;
run;
You can also mix step1 and step2 in a single step:
data want;
set Rawdata;
array Ind_Expose_Mon (6);
do k=1 to dim(Ind_Expose_Mon);
if k<=No_Mon_expose then Ind_Expose_Mon(k)=1;
else Ind_Expose_Mon(k)=0;
end;
array score (6);
do i=1 to dim(score);
if score(i)=11 then do;
do j = (i+1) to dim(Ind_Expose_Mon);
Ind_Expose_Mon(j)=0;
end;
end;
end;
drop i j k;
run;
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.