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

Hello.

I am revisiting the SAS codes I used in the past and have difficulty interpreting my previous codes.

Can anyone tell me the difference between the two codes below? Thank you.

 

data a1.prediss1;
set a1.prediss;
where Error=0 And (Phoneme_stress in (0, 2, 3, 4, 5)) And phase_info1 in (1, 3);
run;

 

versus


data a1.Prediss1;
set a1.Prediss;
where error=0 And phase_info1 in (1, 3);
if Phoneme_stress in (2, 3, 4, 5) then delete;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

The difference in the logic (rows selected):

In the first case rows must meet the condition: Phoneme_stress in (0, 2, 3, 4, 5)

In the 2nd case you delete all rows that meet condition: Phoneme_stress in  (2, 3, 4, 5)

 

If you would use the syntax of case1 for the logic in case two it would need to look like:

where Error=0 And Phoneme_stress NOT in (2, 3, 4, 5) And phase_info1 in (1, 3);

 

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

The difference in the logic (rows selected):

In the first case rows must meet the condition: Phoneme_stress in (0, 2, 3, 4, 5)

In the 2nd case you delete all rows that meet condition: Phoneme_stress in  (2, 3, 4, 5)

 

If you would use the syntax of case1 for the logic in case two it would need to look like:

where Error=0 And Phoneme_stress NOT in (2, 3, 4, 5) And phase_info1 in (1, 3);

 

upstream
Fluorite | Level 6

Thank you so much for your help.

ballardw
Super User

Here's a learning tip: comment code.

You can insert text in the middle of code that does not get executed if you place it between /*   and */ (yes I know there are other comments but get one started.

So when you write code you can insert what it is intended to do (up date when the code actually works)

Your comment does not have to paraphrase exactly what the code does but a good idea of why usually jogs a memory enough. Following is a example:

data a1.prediss1;
   set a1.prediss;
   /* select the records with no errors and Phoneme_stress and phase_info 
     for <state specific purpose>
  */
  where Error=0 And (Phoneme_stress in (0, 2, 3, 4, 5)) And phase_info1 in (1, 3);
run;
upstream
Fluorite | Level 6

Thank you for your advice. I added those comments to my code. Thank you.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 662 views
  • 2 likes
  • 3 in conversation