Please, I need help creating a single categorical variables from several categorical variables. The categorical variables from which I would like to create a single variable are Agitation(1, 0), Akathisia(1, 0), Anxiety_Depression(1, 0), Arrhythmia(1, 0), Cough(1, 0), Dizziness(1, 0), Home_medication(1, 0), Other(1, 0), Pain(1, 0), Psychosis(1, 0), Secretion(1, 0) and High_Bld_Pressure(1, 0). They are mutually exclusive. I would like to create a variable called indication that will have the disease name as observation eg(Agitiation, Cough, Dizziness etc). The code I have below seems to exclude some observation.
Data long232c;
set long232b;
if Agitation=1 then Indication='Agitation';
if Akathisia=1 then Indication='Akathisia';
if Anxiety_Depression=1 then Indication='Anxiety_Dep';
if Arrhythmia=1 then Indication='Arrhythmia';
if Cough=1 then Indication='Cough';
if Dizziness=1 then Indication='Dizziness';
if Fever=1 then Indication='Fever';
if High_Bld_Pressure=1 then Indication='HBP';
if Home_medication ne . and Home_medication=1 then Indication='Home_med';
if Nausea_Vomiting=1 then Indication='Nausea_Vom';
if Other= 1 then Indication='Other';
if Pain=1 then Indication='Pain';
if Psychosis=1 then Indication='Psychosis';
if Secretion=1 then Indication='Secretion';
if Seizure=1 then Indication='Seizure';
if Sleep_disturbance=1 then Indication='Sleep_dist';
if Shortness_of_breath=1 then Indication='SOB';
if Spasm=1 then Indication='Spasm';
if Swelling=1 then Indication='Swelling';
if Withdrawal=1 then Indication='Withdrawal';run;
proc freq data=long232c;
table Indication Agitation Akathisia Anxiety_Depression Arrhythmia Cough Dizziness Home_medication Other Pain Psychosis Secretion High_Bld_Pressure;run;
Thank you
Data long232c;
set long232b;
array _issues(*) agitation --withdrawal;
length indications $512.;
call missing(indications);
do i=1 to dim(_issues);
if _issues(i) = 1 then do;
indications = catx(",", trim(indications), vname(_issues(i)));
end;
end;
run;
Key concepts here are arrays, the usage of the VNAME function to get the disease from the variable name and CATX() to append the data.
Untested but should get you started.
@UcheOkoro wrote:
Please, I need help creating a single categorical variables from several categorical variables. The categorical variables from which I would like to create a single variable are Agitation(1, 0), Akathisia(1, 0), Anxiety_Depression(1, 0), Arrhythmia(1, 0), Cough(1, 0), Dizziness(1, 0), Home_medication(1, 0), Other(1, 0), Pain(1, 0), Psychosis(1, 0), Secretion(1, 0) and High_Bld_Pressure(1, 0). They are mutually exclusive. I would like to create a variable called indication that will have the disease name as observation eg(Agitiation, Cough, Dizziness etc). The code I have below seems to exclude some observation.
Data long232c; set long232b; if Agitation=1 then Indication='Agitation'; if Akathisia=1 then Indication='Akathisia'; if Anxiety_Depression=1 then Indication='Anxiety_Dep'; if Arrhythmia=1 then Indication='Arrhythmia'; if Cough=1 then Indication='Cough'; if Dizziness=1 then Indication='Dizziness'; if Fever=1 then Indication='Fever'; if High_Bld_Pressure=1 then Indication='HBP'; if Home_medication ne . and Home_medication=1 then Indication='Home_med'; if Nausea_Vomiting=1 then Indication='Nausea_Vom'; if Other= 1 then Indication='Other'; if Pain=1 then Indication='Pain'; if Psychosis=1 then Indication='Psychosis'; if Secretion=1 then Indication='Secretion'; if Seizure=1 then Indication='Seizure'; if Sleep_disturbance=1 then Indication='Sleep_dist'; if Shortness_of_breath=1 then Indication='SOB'; if Spasm=1 then Indication='Spasm'; if Swelling=1 then Indication='Swelling'; if Withdrawal=1 then Indication='Withdrawal';run; proc freq data=long232c; table Indication Agitation Akathisia Anxiety_Depression Arrhythmia Cough Dizziness Home_medication Other Pain Psychosis Secretion High_Bld_Pressure;run;
Thank you
Data long232c;
set long232b;
array _issues(*) agitation --withdrawal;
length indications $512.;
call missing(indications);
do i=1 to dim(_issues);
if _issues(i) = 1 then do;
indications = catx(",", trim(indications), vname(_issues(i)));
end;
end;
run;
Key concepts here are arrays, the usage of the VNAME function to get the disease from the variable name and CATX() to append the data.
Untested but should get you started.
@UcheOkoro wrote:
Please, I need help creating a single categorical variables from several categorical variables. The categorical variables from which I would like to create a single variable are Agitation(1, 0), Akathisia(1, 0), Anxiety_Depression(1, 0), Arrhythmia(1, 0), Cough(1, 0), Dizziness(1, 0), Home_medication(1, 0), Other(1, 0), Pain(1, 0), Psychosis(1, 0), Secretion(1, 0) and High_Bld_Pressure(1, 0). They are mutually exclusive. I would like to create a variable called indication that will have the disease name as observation eg(Agitiation, Cough, Dizziness etc). The code I have below seems to exclude some observation.
Data long232c; set long232b; if Agitation=1 then Indication='Agitation'; if Akathisia=1 then Indication='Akathisia'; if Anxiety_Depression=1 then Indication='Anxiety_Dep'; if Arrhythmia=1 then Indication='Arrhythmia'; if Cough=1 then Indication='Cough'; if Dizziness=1 then Indication='Dizziness'; if Fever=1 then Indication='Fever'; if High_Bld_Pressure=1 then Indication='HBP'; if Home_medication ne . and Home_medication=1 then Indication='Home_med'; if Nausea_Vomiting=1 then Indication='Nausea_Vom'; if Other= 1 then Indication='Other'; if Pain=1 then Indication='Pain'; if Psychosis=1 then Indication='Psychosis'; if Secretion=1 then Indication='Secretion'; if Seizure=1 then Indication='Seizure'; if Sleep_disturbance=1 then Indication='Sleep_dist'; if Shortness_of_breath=1 then Indication='SOB'; if Spasm=1 then Indication='Spasm'; if Swelling=1 then Indication='Swelling'; if Withdrawal=1 then Indication='Withdrawal';run; proc freq data=long232c; table Indication Agitation Akathisia Anxiety_Depression Arrhythmia Cough Dizziness Home_medication Other Pain Psychosis Secretion High_Bld_Pressure;run;
Thank you
Yes, I noticed that were not mutually exclusive after running the code with the array statement. I was over writing the conditions. Thank you for this observation
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.