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
;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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