My code is below. The error message is also shown. How do I fix the code so it will delete Group B.
Code:
DATA patients;
INPUT PatientID Group $ ;
DATALINES;
4165 A
2255 B
3312 C
5689 C
1287 A
5454 A
6672 C
8521 B
8936 C
5764 B
;
IF Group = 'B' THEN DELETE;
RUN;
Error:
ERROR 180-322: Statement is not valid or it is used out of proper order.
Your IF statement is in the wrong place!
DATA patients;
INPUT PatientID Group $ ;
IF Group = 'B' THEN DELETE;
DATALINES;
4165 A
2255 B
3312 C
5689 C
1287 A
5454 A
6672 C
8521 B
8936 C
5764 B
;
RUN;
Koen
Your IF statement is in the wrong place!
DATA patients;
INPUT PatientID Group $ ;
IF Group = 'B' THEN DELETE;
DATALINES;
4165 A
2255 B
3312 C
5689 C
1287 A
5454 A
6672 C
8521 B
8936 C
5764 B
;
RUN;
Koen
When you have in-line data the data step ends when the data begins.
So you have put your IF statement in between the data step and the next step.
That is why I would suggest that you get in the habit of NOT adding a RUN: statement after the in-line data lines. It just confuses novice SAS programmers into thinking it is part of the data step.
DATA patients;
INPUT PatientID Group $ ;
IF Group = 'B' THEN DELETE;
DATALINES;
4165 A
2255 B
3312 C
5689 C
1287 A
5454 A
6672 C
8521 B
8936 C
5764 B
;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.