BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
_maldini_
Barite | Level 11

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"

Screen Shot 2021-10-25 at 5.40.48 PM.png

I've tried if-then-delete and where clauses and can't figure it out.

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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).

 

View solution in original post

4 REPLIES 4
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

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

_maldini_
Barite | Level 11

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;

Screen Shot 2021-10-25 at 7.29.28 PM.png

Astounding
PROC Star

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).

 

ballardw
Super User

@_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;

Screen Shot 2021-10-25 at 7.29.28 PM.png


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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 4 replies
  • 1215 views
  • 9 likes
  • 4 in conversation