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
;
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.