BookmarkSubscribeRSS Feed
PravinMishra
Quartz | Level 8

Hi 

 

I am trying below code to subset the but not getting result as expected.

 

DATA A;
INFILE DATALINES DSD DLM=' ';
INPUT A B;
DATALINES;
1 1
1 2
1 3
1 4
1 5
1 6
1 7
;
RUN;
DATA X Y;
SET A;
IF A=1 AND B IN (1,2,3) THEN OUTPUT X;
IF A=1 AND B IN (4,5,6,7) THEN OUTPUT Y;
RUN;

 

 

expected result:

Data set X:

1 1
1 2
1 3

Data set Y:
1 4
1 5
1 6
1 7

 

can anyone please let me know where I am doing wrong.

3 REPLIES 3
Kurt_Bremser
Super User

Take a look at dataset a, if it really looks as expected.

Next, inspect the log of both steps; if that does not give you a clue, post the log and the list outputs of both datasets.

Astounding
PROC Star

Your expectations are right on the money.

 

Many times, the board can diagnose the error with no help ... no log, no PROC PRINT results, no PROC CONTENTS results.  Unfortunately, this is not one of those times.  If you didn't get what you expected, you may have to show what the results actually were.

ballardw
Super User

When I run your code as posted I get exactly the desired result posted.

 

If your unexpected result is coming from a larger different data set A or the logic is more complex then that could be the diffrence. If you expect an output record everytime variable A=1 it may be that variable B has unexpected values such as missing or out of range of the exact values placed in the IN operator arguement.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 3 replies
  • 871 views
  • 0 likes
  • 4 in conversation