I have a few questions about comma delimited data, do-loops and dummy variables. (SAS 9.4) I have a data set that includes multiple diagnoses in one column separated by commas: Obs CMRDiagnosis 1 Apical HCM,Fibrosis 2 Sarcoidosis,DCM 3 Amyloidosis 4 MI,Fibrosis 5 Myocarditis,DCM 6 Myocarditis 7 Valvular dz 8 9 MI,LVH 10 DCM 11 HCM,Fibrosis,Valvular dz Since each person can have more than one diagnosis (max 6 diagnoses per person, 13 diagnoses possible) I would like to create a dummy variable for each of the 13 diagnosis, (labeled as "_MR" aka the source of the diagnosis, to distinguish from other diagnosis variables). Not knowing how to separate the comma delimited variables, I separated them in Excel as DX1-DX6. After importing the new data, I did the following: select (DX1);
when ('Amyloidosis') Amyloid_MR =1;
when ('Apical HCM') Ap_HCM_MR =1;
when ('CM') CM_MR =1;
when ('DCM') DCM_MR =1;
when ('Fibrosis') Fibrosis_MR =1;
when ('HCM') HCM_MR =1;
when ('LVH') LVH_MR =1;
when ('MI') MI_MR =1;
when ('Myocarditis') Myocarditis_MR =1;
when ('Noncompaction') Noncompaction_MR =1;
when ('Pericardial dz') Pericardial_MR =1;
when ('Sarcoidosis') Sarcoidosis_MR =1;
when ('Valvular dz') Valvular_MR =1;
otherwise; end; 1. Is there a better way to accomplish this for all DX vars with a do-loop (or macro) to execute the above code without copy-pasting 5 additional times for each DX? 2. How would I separate the comma delimited data? 3. The above code leaves you with variables like "Valvular_MR" where observations are either "1" or " ". How can I execute this code while also replacing the missing rows with "0" as appropriate? Thank you!
... View more