BookmarkSubscribeRSS Feed
kkLaRue81
Calcite | Level 5

I am new to SAS

I have a dataset created in redcap. it has been imported into SAS studio as a csv file

it is patient data and the goal is to determine if patients who identify as transgender/Non binary have a rate of surgical complications less than, equal to, or higher than patients who identify as cisgender when it comes to hysterectomy

 

for each patient I have collected information about whether they had an intraoperative complication, postoperative complication, reoperation, or readmission

For Intraoperative complications there are 5 different complications being looked at intraop_complication__1 (vascular injury), intraop_complication__2 (GI injury), intraop_complications___4 ('Intraoperative consult due to complication), label intraop_complications___97(Other). For postop the data is similar with 1-8, 97. for reoperation and for readmission it's either yes or no

 

I want to create a composite variable. Its name will be surgical complications. It will be a column that shows either a Yes or No. It will be Yes if a patient had any complication (any single positive value in the intraop, postop, reoperation, or readmission categories) or No (no positive value for any of the aforementioned categories)

 

I have tried if-then statements with or/and, if then else statements, array statements and I cannot get this to work. I got it close to working but then it stopped and started just putting a "." and I could not figure out why it stopped working. I am at my wits end and willing to pay someone to help me at this point (if that is allowed). 

 

Any suggestions (or takers to hop on zoom and try to help me figure it out for compensation?)

 

data WORK.REDCAP;
infile datalines dsd truncover;
input record_id:$500. age:BEST12. gender:GENDER_. gender_other:$500. bmi:BEST12. race___1:RACE___1_. race___2:RACE___2_. race___3:RACE___3_. race___4:RACE___4_. race___5:RACE___5_. ethnicity:ETHNICITY_. insurance:INSURANCE_. testosterone_use:TESTOSTERONE_USE_. dx_hyst:DX_HYST_. dx_hyst_oth:$500. route_hyst:ROUTE_HYST_. asa_class:ASA_CLASS_. oophorectomy:OOPHORECTOMY_. comorbid_conditions___1:COMORBID_CONDITIONS___1_. comorbid_conditions___2:COMORBID_CONDITIONS___2_. comorbid_conditions___3:COMORBID_CONDITIONS___3_. comorbid_conditions___4:COMORBID_CONDITIONS___4_. comorbid_conditions___5:COMORBID_CONDITIONS___5_. comorbid_conditions___6:COMORBID_CONDITIONS___6_. comorbid_conditions___7:COMORBID_CONDITIONS___7_. comorbid_conditions___8:COMORBID_CONDITIONS___8_. comorbid_conditions___9:COMORBID_CONDITIONS___9_. comorbid_conditions___10:COMORBID_CONDITIONS___10_. comorbid_conditions___11:COMORBID_CONDITIONS___11_. smoking:SMOKING_. preop_hematocrit:$500. hx_abnormal_pap:HX_ABNORMAL_PAP_. cystoscopy:CYSTOSCOPY_. cystoscopy_normal:CYSTOSCOPY_NORMAL_. intraop_complications___1:INTRAOP_COMPLICATIONS___1_. intraop_complications___2:INTRAOP_COMPLICATIONS___2_. intraop_complications___3:INTRAOP_COMPLICATIONS___3_. intraop_complications___4:INTRAOP_COMPLICATIONS___4_. intraop_complications___97:INTRAOP_COMPLICATIONS___97_. intraop_complications_other:$500. operative_time:BEST12. postop_complications___1:POSTOP_COMPLICATIONS___1_. postop_complications___2:POSTOP_COMPLICATIONS___2_. postop_complications___3:POSTOP_COMPLICATIONS___3_. postop_complications___4:POSTOP_COMPLICATIONS___4_. postop_complications___5:POSTOP_COMPLICATIONS___5_. postop_complications___6:POSTOP_COMPLICATIONS___6_. postop_complications___7:POSTOP_COMPLICATIONS___7_. postop_complications___8:POSTOP_COMPLICATIONS___8_. postop_complications___97:POSTOP_COMPLICATIONS___97_. postop_complications_oth:$500. reoperation:REOPERATION_. readmission:READMISSION_. data_collection_complete:DATA_COLLECTION_COMPLETE_. gender_01_:GENDER_01_. race:$30.;
datalines4;
1,29,Transgender,,36.72,No,No,yes,No,No,Not Hispanic or Latino or Spanish Origin,Public,Yes,Gender Dysphoria,,LAVH,2,Yes,No,No,No,No,No,No,No,No,No,No,No,Never smoked a single cigarette,44.9,No,No,,No,No,No,No,No,,211,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,Black
2,38,Transgender,,24.28,No,No,yes,No,No,Not Hispanic or Latino or Spanish Origin,Public,Yes,Uterine Fibroids,,Open,2,No,No,No,No,No,No,No,No,No,No,No,No,Never smoked a single cigarette,48.2,No,Yes,Yes,No,No,No,No,No,,267,No,No,No,No,No,No,yes,No,No,,No,No,Complete,gender diverse,Black
3,25,Transgender,,28.7,No,No,No,No,yes,Not Hispanic or Latino or Spanish Origin,Private,Yes,Gender Dysphoria,,TLH,2,Yes,No,No,No,No,No,No,No,No,No,No,No,Smoke very sporadically and/or on rare occasions,39.7,No,Yes,Yes,No,No,No,No,No,,166,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,White
4,50,Transgender,,29.66,No,No,No,No,yes,Not Hispanic or Latino or Spanish Origin,Private,Yes,Pelvic Pain,,TLH,2,Yes,No,No,No,No,No,No,No,No,No,No,No,Never smoked a single cigarette,56.2,No,Yes,Yes,No,No,No,No,No,,207,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,White
5,43,Transgender,,34.4,No,No,No,No,yes,Not Hispanic or Latino or Spanish Origin,Public,Yes,Pelvic Pain,,TVH,3,Yes,No,No,No,No,yes,No,No,No,No,No,No,Currently smokes,53.2,No,No,,No,No,No,No,No,,231,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,White

 

15 REPLIES 15
kkLaRue81
Calcite | Level 5

Hi everyone

I am a 100% novice with SAS and I have a question.

I am hoping to combine data columns that have like data. If you take a look at the uploaded data table I want to combine intraoperative complications, postoperative complications, reoperation and readmission into one single variable that will be called surgical complications and it will be a dichotomous variable: Yes or No

 

I tried a length function but it didn't work:

length surgical complications $30.;

if intraop_complications___3 = 1 then surgical complications = 'Yes';

if intraop_complications___4 = 1 then surgical complications = 'Yes';

if intraop_complications___97 = 1 then surgical complications = 'Yes';

if intraop_complications___1=0 then surgical complications = 'No';

if intraop_complications___2=0 then surgical complications = 'No';

if intraop_complications___3=0 then surgical complications = 'No';

if intraop_complications___4=0 then surgical complications = 'No';

if intraop_complications___97=0 then surgical complications = 'No';

 

I would appreciate any help, suggestions or pointing me to youtube to a good tutorial 

 

thank you

PaigeMiller
Diamond | Level 26

Your code has variables named like

 

intraop_complications___3

 

and as far as I can see, this is not a variable in your data set. Please explain further.

 

Your response variable surgical complications is not a valid SAS variable name, which cannot have spaces. You could name it surgical_complications.

 

Also, please do not provide data in attachments. Please provide data as SAS data step code, you can type it in yourself, or follow these instructions and then paste the code into your reply.

--
Paige Miller
kkLaRue81
Calcite | Level 5
thanks for the response. I think I did this part right 
the intraop_complications__1 and so forth are the original data and I made labels so that it looks more reader friendly in a table

data WORK.REDCAP;
infile datalines dsd truncover;
input record_id:$500. age:BEST12. gender:GENDER_. gender_other:$500. bmi:BEST12. race___1:RACE___1_. race___2:RACE___2_. race___3:RACE___3_. race___4:RACE___4_. race___5:RACE___5_. ethnicity:ETHNICITY_. insurance:INSURANCE_. testosterone_use:TESTOSTERONE_USE_. dx_hyst:DX_HYST_. dx_hyst_oth:$500. route_hyst:ROUTE_HYST_. asa_class:ASA_CLASS_. oophorectomy:OOPHORECTOMY_. comorbid_conditions___1:COMORBID_CONDITIONS___1_. comorbid_conditions___2:COMORBID_CONDITIONS___2_. comorbid_conditions___3:COMORBID_CONDITIONS___3_. comorbid_conditions___4:COMORBID_CONDITIONS___4_. comorbid_conditions___5:COMORBID_CONDITIONS___5_. comorbid_conditions___6:COMORBID_CONDITIONS___6_. comorbid_conditions___7:COMORBID_CONDITIONS___7_. comorbid_conditions___8:COMORBID_CONDITIONS___8_. comorbid_conditions___9:COMORBID_CONDITIONS___9_. comorbid_conditions___10:COMORBID_CONDITIONS___10_. comorbid_conditions___11:COMORBID_CONDITIONS___11_. smoking:SMOKING_. preop_hematocrit:$500. hx_abnormal_pap:HX_ABNORMAL_PAP_. cystoscopy:CYSTOSCOPY_. cystoscopy_normal:CYSTOSCOPY_NORMAL_. intraop_complications___1:INTRAOP_COMPLICATIONS___1_. intraop_complications___2:INTRAOP_COMPLICATIONS___2_. intraop_complications___3:INTRAOP_COMPLICATIONS___3_. intraop_complications___4:INTRAOP_COMPLICATIONS___4_. intraop_complications___97:INTRAOP_COMPLICATIONS___97_. intraop_complications_other:$500. operative_time:BEST12. postop_complications___1:POSTOP_COMPLICATIONS___1_. postop_complications___2:POSTOP_COMPLICATIONS___2_. postop_complications___3:POSTOP_COMPLICATIONS___3_. postop_complications___4:POSTOP_COMPLICATIONS___4_. postop_complications___5:POSTOP_COMPLICATIONS___5_. postop_complications___6:POSTOP_COMPLICATIONS___6_. postop_complications___7:POSTOP_COMPLICATIONS___7_. postop_complications___8:POSTOP_COMPLICATIONS___8_. postop_complications___97:POSTOP_COMPLICATIONS___97_. postop_complications_oth:$500. reoperation:REOPERATION_. readmission:READMISSION_. data_collection_complete:DATA_COLLECTION_COMPLETE_. gender_01_:GENDER_01_. race:$30.;
datalines4;
1,29,Transgender,,36.72,No,No,yes,No,No,Not Hispanic or Latino or Spanish Origin,Public,Yes,Gender Dysphoria,,LAVH,2,Yes,No,No,No,No,No,No,No,No,No,No,No,Never smoked a single cigarette,44.9,No,No,,No,No,No,No,No,,211,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,Black
2,38,Transgender,,24.28,No,No,yes,No,No,Not Hispanic or Latino or Spanish Origin,Public,Yes,Uterine Fibroids,,Open,2,No,No,No,No,No,No,No,No,No,No,No,No,Never smoked a single cigarette,48.2,No,Yes,Yes,No,No,No,No,No,,267,No,No,No,No,No,No,yes,No,No,,No,No,Complete,gender diverse,Black
3,25,Transgender,,28.7,No,No,No,No,yes,Not Hispanic or Latino or Spanish Origin,Private,Yes,Gender Dysphoria,,TLH,2,Yes,No,No,No,No,No,No,No,No,No,No,No,Smoke very sporadically and/or on rare occasions,39.7,No,Yes,Yes,No,No,No,No,No,,166,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,White
4,50,Transgender,,29.66,No,No,No,No,yes,Not Hispanic or Latino or Spanish Origin,Private,Yes,Pelvic Pain,,TLH,2,Yes,No,No,No,No,No,No,No,No,No,No,No,Never smoked a single cigarette,56.2,No,Yes,Yes,No,No,No,No,No,,207,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,White
5,43,Transgender,,34.4,No,No,No,No,yes,Not Hispanic or Latino or Spanish Origin,Public,Yes,Pelvic Pain,,TVH,3,Yes,No,No,No,No,yes,No,No,No,No,No,No,Currently smokes,53.2,No,No,,No,No,No,No,No,,231,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,White
PaigeMiller
Diamond | Level 26

Whoever created that data set used lots of custom informats that I don't have, so I can't work with your data.

 

However, I will guess that the values of all the intraop_complication variables are 1 or 0 because of those informats. (And if my guess is wrong, then again I can't do anything here).

 

if intraop_complications___3 = 1 or 
if intraop_complications___4 = 1 or
if intraop_complications___97 = 1 then surgical_complications=1;
else surgical_complications=0;

Now, there's no way I can test this, because I can't run your code. But it seems as if this will do what you want.

 

There's also logical errors here, where your original code seems to set different values of surgical_complications depending one which intraop complications are present, and so surgical complications could be both 1 and 0 for the same patient.

 

--
Paige Miller
kkLaRue81
Calcite | Level 5
The data was imported from a redcap form. You are correct in that each person could have one or more intraop complications (1= vascular injury, 2=GI injury, 3=GU injury, 4=Intraoperative consult due to complication 97=Other) therefore each person could be "present/yes=1" or "not presentno=0" for each
I hope that makes it clear

I will try out the solution you posted as it does look like what I am trying to get at.
basically, I want to combine the data (intraop complications, postop complications, reoperation, and readmission) because the number of complications is so small limiting analysis and knowing that they had or did not have "any complication" is beneficial.

thank you for your help!
mkeintz
PROC Star

What if interop_complications__3=1 and interop_complications__4=0?  Your code suggests that surgical_complications could then be both a "Yes" and a "No"..

 

Since these vars all appear to be a 1 or 0, I suggest you list - in an array statement - all those variables for which a value of 1 means surgical_complications='Yes'.   That's the array one_means_yes below.  And if there are any variables in which a value of 0 would also imply a "Yes", you could have a second array statement, like zero_means_yes with variables out of my imagination below.

 

You could also make one of two more array statements (zero_means_no  and one_means_no below) to capture those cases that imply surgical_complications='No'.

 

If you can remove the potential contradictory implications in your original task description, you could use code such as the below: 

 

data want;
  set redcap;
  array one_means_yes  {*}  interop_conditions__3  interop_conditions__4  interop_conditions__97; 
  array zero_means_yes {*}  xxx yyyy zzz ;
  array one_means_no   {*}  aaa bbbb ccc ;
  array zero_means_no  {*}  interop_conditions__1  interop_conditions__2  ... ; 

  if whichn(1, of one_means_yes{*})  then surgical_complications="Yes";  else
  if whichn(0, of zero_means_yes{*}) then surgical_complications="Yes";  else
  if whichn(0, of zero_means_no{*})  then surgical_complications="No";   else
  if whichn(1, of one_means_no{*})   then surgical_complications="No"; 

run;

The whichn function above searches the second through last arguments for the value specified in the first argument, and returns the position of the successful search.  If unsuccessful, it returns a zero.  The IF statement containing the whichn function is "true" for any non-zero result of the whichn.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
kkLaRue81
Calcite | Level 5

@mkeintz wrote:

What if interop_complications__3=1 and interop_complications__4=0?  Your code suggests that surgical_complications could then be both a "Yes" and a "No"..

 

wanted to clarify: If the above is true that intraop_complications__3=1 and intraop_complication__4=0 then the code should have surgical_complications ONLY as a Yes for that patient. The patient either has had a complication (intraop, postop, reoperation, readmission) Yes=1 or has not (No=0) cannot be both. 

kkLaRue81
Calcite | Level 5

data want;
set redcap;
array one_means_yes {*} intraop_complications__3 intraop_complications__4 intraop_complications__97;
array zero_means_no {*} intraop_complications__1 intraop_complications__2;
if whichn(1, of one_means_yes{*}) then surgical_complications="Yes"; else
if whichn(0, of zero_means_no{*}) then surgical_complications="No"; else
run;

 

would this work?

mkeintz
PROC Star

@kkLaRue81 wrote:

data want;
set redcap;
array one_means_yes {*} intraop_complications__3 intraop_complications__4 intraop_complications__97;
array zero_means_no {*} intraop_complications__1 intraop_complications__2;
if whichn(1, of one_means_yes{*}) then surgical_complications="Yes"; else
if whichn(0, of zero_means_no{*}) then surgical_complications="No"; else
run;

 

would this work?


As a purely technical matter it would NOT work.  You have to remove the last "else".

 

On a more general issue, if there are more variables to be examined to assign a value to surgical_complications then you need to add them to the appropriate array statement.

 

And what if none of the one_means_yes variables is a 1, and none of the zero_means_no is a zero?    Is that possible?  If so, then the surgical_complications variable would be a blank.   You have to be the person to determine whether that's ok.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
kkLaRue81
Calcite | Level 5
got it. 

 

And what if none of the one_means_yes variables is a 1, and none of the zero_means_no is a zero?    Is that possible?  If so, then the surgical_complications variable would be a blank.   You have to be the person to determine whether that's ok.

 

the variables have to be yes/1 or no/0, all of the records/patients have data collected for the variable. they will either have a complication (at least one or more of the complications will be yes/1) or they will not have a complication (all values for a patient will be no/0). most patients will have all no/0 so surgical_complications would be No for that patient


 

mkeintz
PROC Star

@kkLaRue81 wrote:

@mkeintz wrote:

What if interop_complications__3=1 and interop_complications__4=0?  Your code suggests that surgical_complications could then be both a "Yes" and a "No"..

 

wanted to clarify: If the above is true that intraop_complications__3=1 and intraop_complication__4=0 then the code should have surgical_complications ONLY as a Yes for that patient. The patient either has had a complication (intraop, postop, reoperation, readmission) Yes=1 or has not (No=0) cannot be both. 


I take your response to mean that the any indication that surgical_complications is a yes preempts any indication that it is a no.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
kkLaRue81
Calcite | Level 5


I take your response to mean that the any indication that surgical_complications is a yes preempts any indication that it is a no.


Yes, That is correct.

Patrick
Opal | Level 21

@kkLaRue81 

I've taken your sample data and replaced the informats with something also available to us. 

I've used informat $upcase3. for all columns with values Yes or No to ensure that in the resulting table all these values are uppercase.

data have;
  infile datalines dsd truncover;
  input 
    record_id:$40. age:BEST12. gender:$40. gender_other:$40. bmi:BEST12. race___1:$upcase3. race___2:$upcase3. race___3:$upcase3. race___4:$upcase3. race___5:$upcase3. 
    ethnicity:$40. insurance:$40. testosterone_use:$upcase3. dx_hyst:$40. dx_hyst_oth:$40. route_hyst:$40. asa_class:$40. 
    oophorectomy:$upcase3. comorbid_conditions___1:$upcase3. comorbid_conditions___2:$upcase3. comorbid_conditions___3:$upcase3. 
    comorbid_conditions___4:$upcase3. comorbid_conditions___5:$upcase3. comorbid_conditions___6:$upcase3. 
    comorbid_conditions___7:$upcase3. comorbid_conditions___8:$upcase3. comorbid_conditions___9:$upcase3. 
    comorbid_conditions___10:$upcase3. comorbid_conditions___11:$upcase3. smoking:$40. preop_hematocrit:$40. 
    hx_abnormal_pap:$upcase3. cystoscopy:$upcase3. cystoscopy_normal:$upcase3.
    intraop_complications___2:$upcase3. intraop_complications___3:$upcase3. intraop_complications___4:$upcase3. 
    intraop_complications___97:$upcase3. intraop_complications_other:$upcase3. operative_time:BEST12. postop_complications___1:$upcase3. 
    postop_complications___2:$upcase3. postop_complications___3:$upcase3. postop_complications___4:$upcase3. 
    postop_complications___5:$upcase3. postop_complications___6:$upcase3. postop_complications___7:$upcase3. 
    postop_complications___8:$upcase3. postop_complications___97:$upcase3. postop_complications_oth:$upcase3. 
    reoperation:$upcase3. readmission:$upcase3. data_collection_complete:$upcase3. gender_01_:$40. race:$40.
    ;
/*    keep record_id intraop_complications___: postop_complications___:  reoperation readmission;*/
  ;
  datalines4;
1,29,Transgender,,36.72,No,No,yes,No,No,Not Hispanic or Latino or Spanish Origin,Public,Yes,Gender Dysphoria,,LAVH,2,Yes,No,No,No,No,No,No,No,No,No,No,No,Never smoked a single cigarette,44.9,No,No,,No,No,No,No,No,,211,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,Black
2,38,Transgender,,24.28,No,No,yes,No,No,Not Hispanic or Latino or Spanish Origin,Public,Yes,Uterine Fibroids,,Open,2,No,No,No,No,No,No,No,No,No,No,No,No,Never smoked a single cigarette,48.2,No,Yes,Yes,No,No,No,No,No,,267,No,No,No,No,No,No,yes,No,No,,No,No,Complete,gender diverse,Black
3,25,Transgender,,28.7,No,No,No,No,yes,Not Hispanic or Latino or Spanish Origin,Private,Yes,Gender Dysphoria,,TLH,2,Yes,No,No,No,No,No,No,No,No,No,No,No,Smoke very sporadically and/or on rare occasions,39.7,No,Yes,Yes,No,No,No,No,No,,166,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,White
4,50,Transgender,,29.66,No,No,No,No,yes,Not Hispanic or Latino or Spanish Origin,Private,Yes,Pelvic Pain,,TLH,2,Yes,No,No,No,No,No,No,No,No,No,No,No,Never smoked a single cigarette,56.2,No,Yes,Yes,No,No,No,No,No,,207,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,White
5,43,Transgender,,34.4,No,No,No,No,yes,Not Hispanic or Latino or Spanish Origin,Public,Yes,Pelvic Pain,,TVH,3,Yes,No,No,No,No,yes,No,No,No,No,No,No,Currently smokes,53.2,No,No,,No,No,No,No,No,,231,No,No,No,No,No,No,No,No,No,,No,No,Complete,gender diverse,White
;;;

 

Using above sample data and if I've got your requirement right then something like below should work.

data want;
  length surgical_complications $3.;
  set have;
  array a_outcome {*} intraop_complications___: postop_complications___: reoperation readmission;
  if whichc('YES',of a_outcome[*]) then surgical_complications='YES';
  else surgical_complications='NO';
run;

 

 

kkLaRue81
Calcite | Level 5

I tried this solution but it has all patients as NO surgical complications

 

If there is anyone willing to get on zoom to help I would appreciate it. this is the last thing that I need to have completed and I've been struggling for 3 days now with this and really need a resolution. I am happy to pay for time. 

 

thanks

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 15 replies
  • 1457 views
  • 3 likes
  • 4 in conversation