BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10
data a;
input x y;
cards;
1 3
4 5
6 7
;
data b;
input x y;
cards;
1 4
4 7
8 9
;

data test;
   set a b;
   if x=1 then delete;
run;

I have a test code above. I want to know the process flow of this program. Does if statment acts separately on data sets i.e. read observation from a  and apply if stament on each observation and after finishing on a starts on b?  

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Test it by adding N=_n_; after the SET but before the if.

 

And temporary variables are just that, they would not be in the output, just like _n_ isn't unless assigned to another variable that isn't dropped from the data.

View solution in original post

3 REPLIES 3
ballardw
Super User

Unless you specifically tell it to examine values from only one of the data sets then any record with a value of 1 for x will be deleted.

You can use the IN dataset option to identify which dataset contributed the observation if that is needed. The IN option creates temporary variables that can be used for testing membership. The example below says to delete only if the record came from dataset b. The IN for dataset A would be completely optional for this code but provided as an example. If you are MERGEing datasets you can use code like If InA and InB ... to see if the record has contributions from both (or more than two) datasets.

data test;
   set a (in= inA)
       b (in= inB);
   if inB AND x=1 then delete;
run;

 

SAS_inquisitive
Lapis Lazuli | Level 10

Thanks, ballardw.  The code posted above gives me desired result (it deletes from both data sets).  I don't want to create temporary variale now (just for learning purpose) . I wanted to know how the data step worked.  Since set statment in my example stacks a and b together sequentially, does "if " statement operate on each data sets sequentially.  Basically, I want to see what happned during _n_=1? 

ballardw
Super User

Test it by adding N=_n_; after the SET but before the if.

 

And temporary variables are just that, they would not be in the output, just like _n_ isn't unless assigned to another variable that isn't dropped from the data.

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
  • 837 views
  • 1 like
  • 2 in conversation