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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

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

View solution in original post

2 REPLIES 2
sbxkoenk
SAS Super FREQ

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

Tom
Super User Tom
Super User

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
;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 848 views
  • 1 like
  • 3 in conversation