I'd like to delete observations where the following conditions are met:
redcap_event_name = "baseline"
informed_consent_hip_v_0 is missing
informed_consent_hip_v_1 = "incomplete"
I've tried if-then-delete and where clauses and can't figure it out.
Thanks.
Start by cleaning up the errors.
The FORMAT statement ends when it encounters a semicolon. So you have an extra semicolon that should be removed from here:
FORMAT
redcap_event_name $redcap_event_name_.;
since you actually want the FORMAT statement to end here:
informed_consent_hip_v_1 informed_consent_hip_v_1_.;
Also important, it appears that SAS objects to your WHERE statement. Start by confirming whether INFORMED_CONSENT_HIP_V_1_ and INFORMED_CONSENT_HIP_V_0_ are numeric or character. For a numeric variable, checking ="0" would be incorrect (the quotes should be removed).
Do you have any formats applied to this table? I ask because this variable "informed_consent_hip_v_1" appears to be numeric, so you may need that numeric value for which "Incomplete" is the format.
SVH
Yes, there are formats, but I still can't figure it out. I don't understand the format for "redcap_event_name_". Thanks again for your help!
data kb_data;
set redcap;
WHERE redcap_event_name = "baseline_arm_1";
WHERE SAME AND informed_consent_hip_v_1 = "0";
WHERE SAME AND informed_consent_hip_v_0 is missing;
FORMAT
redcap_event_name $redcap_event_name_.;
/* value $redcap_event_name_ baseline_arm_1='baseline' fu_1_arm_1='fu_1' fu_2_arm_1='fu_2'; */
informed_consent_hip_v_1 informed_consent_hip_v_1_.;
/* value informed_consent_hip_v_1_ 0='Incomplete' 1='Unverified' 2='Complete'; */
/* informed_consent_hip_v_0 does not have a format */
run;
Start by cleaning up the errors.
The FORMAT statement ends when it encounters a semicolon. So you have an extra semicolon that should be removed from here:
FORMAT
redcap_event_name $redcap_event_name_.;
since you actually want the FORMAT statement to end here:
informed_consent_hip_v_1 informed_consent_hip_v_1_.;
Also important, it appears that SAS objects to your WHERE statement. Start by confirming whether INFORMED_CONSENT_HIP_V_1_ and INFORMED_CONSENT_HIP_V_0_ are numeric or character. For a numeric variable, checking ="0" would be incorrect (the quotes should be removed).
@_maldini_ wrote:
Yes, there are formats, but I still can't figure it out. I don't understand the format for "redcap_event_name_". Thanks again for your help!
data kb_data; set redcap; WHERE redcap_event_name = "baseline_arm_1"; WHERE SAME AND informed_consent_hip_v_1 = "0"; WHERE SAME AND informed_consent_hip_v_0 is missing; FORMAT redcap_event_name $redcap_event_name_.; /* value $redcap_event_name_ baseline_arm_1='baseline' fu_1_arm_1='fu_1' fu_2_arm_1='fu_2'; */ informed_consent_hip_v_1 informed_consent_hip_v_1_.; /* value informed_consent_hip_v_1_ 0='Incomplete' 1='Unverified' 2='Complete'; */ /* informed_consent_hip_v_0 does not have a format */ run;
Your error messages are because the variable you are using is numeric and you compare it to a character value. When you place digits inside quotes you are intending a CHARACTER comparison. Try = 0;
The second error is because the semicolon after
redcap_event_name $redcap_event_name_.;
ends the Format statement. Remove the ; there and the error should go away.
In future when posting LOG information it is better to copy the log text for the entire procedure or data step, open a text box using the </> and paste the text.
It is very hard to deal with pictures of text. Can't copy/paste, make corrections or such.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.