07-29-2014 02:33 PM
I have16 variables ID, v1-v15 where v1-v15 are coded 0 - no event and 1- event and ID is patient ID.
There are 100 obs.
what I want to be able to do in SAS is:
if an observation = 1 for at least any 2 of the 15 indicator variables then newvar=1
else if an observation =0 less than any 2 of the 15 indicator variables then newvar=0
Any suggestions on how to do this?
07-29-2014 02:58 PM
into :v_list separated by ' '
and name like 'v%';
if sum(of &v_list)>=2 then newvar=1;
07-30-2014 01:58 PM
If you want to skip proc sql you can try this.
if sum(of v>=2 then newvar=1;
This may be a good source for proc sql;
07-29-2014 03:15 PM
Use an array to reference your variables and then check if the sum of the variables is >2.
array v(15) v1-v15;
if sum(of v(*)) >2 then new_var=1;
07-30-2014 12:06 PM
A minor addition to consider with Tom's suggestion is IF you have any records with all of V1 to V15 missing do you want a 0? If so no problem. If however it should return a missing value for your indicator: If you never have all 15 missing then that's good to go also.
If nmiss(of v1-v15) <15 then indicator = 1<sum(of v1-v15);
07-30-2014 02:44 PM
Maybe I am missing something obvious, which happens to me very offten, but in :
indicator = 1 < sum(of v1-v15) ;
The indicator will never be missing, it is a results of boolean operation, so it will be either 0 or 1, and can't be anything else, including missing value. So pre-check the missing status of v1-v15 seems redundant.
while if the purpose is to make sure sum(of v1-v15) not missing, when it is, assign 0 to it, then 0 can be added into the equation: sum(of v1-v15,0)
07-30-2014 05:37 PM
My comment was a gentle reminder that 1) we don't have all of the data and 2) this is a subtle issue with Boolean assignment as all missing V1-V15 would have a sum of missing and 1<missing is false with a 0 assignment to indicator but that MAY not have been the intended result if there were all missing values for the V1-V15.
One potential issue is if the indicator is to be used in a regression model. Having an actual value of 0 if not intended for all missing values of V1-V15 could result in some odd results, especially if a frequent occurrence.
I use these types of recodes frequently have to ensure that I have a missing for the recode with all of the components are missing in most usages.