BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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;


 

 

 

 

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @Ronein 

I am a bit confused with your request:

  • For patient 3, there are 7 values for 6 scores (11 9 8 9 11 11 11). How is it possible to have score1=11 and then other values?
  • Score1 refer to the 1st month of follow-up so it has nothing to do with the 1st month of exposition. What is the rational to mix values? E.g. patient 6 : month1 = exposition; month2-month7 = follow-up (died at month2) -> is that right?

Thank you for the clarifications.

 

Best,

Ronein
Meteorite | Level 14

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;
ed_sas_member
Meteorite | Level 14

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;

 

ed_sas_member
Meteorite | Level 14

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 347 views
  • 1 like
  • 2 in conversation