BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8

 

if product_code in ('CC', 'IL', 'RL', 'VI') and sme=0 
and region ne 'MAC'
and org_code notin ('801', '802', '751')
and ((block_code_1 not in ('A', 'B', 'D', 'W', 'O', 'J', 'Q', 'I')
and block_code_2 not in ('A', 'B', 'D', 'W','O','J','Q','I'))
or ((block_code_1 in ('A','B','D','W','O','J','Q','I')
or block_code_2 in ('A','B','D','W','O','J','Q','I'))
and current_bal >0 and (block_code_1 ne 'A'
and block_code_2 ne 'A'))) then
output; keep account_no region product_code currency cyrrent_delq ind_default block_code_1 date_block_code_1 block_code_2 date_block_code_1 current_bal org_code logo customer_no account_level_rating; run;

Hi I have the above command, what I am not sure is whether the command of keeping certain columns only happen when the if statement is fulfilled? also what does 'output' means here? only keeping the mentioned columns?

2 REPLIES 2
LinusH
Tourmaline | Level 20

Yes, the KEEP statement comes in effect when writing to the output table. 

OUTPUT will tell the data step to output the data with current values set. You can have multiple OUTPUT statements in a data step.

If omitted, an implicit OUTPUT statment is "enforced" (at the end of the data step).

Data never sleeps
Kurt_Bremser
Super User

KEEP is a declarative statement; it is evaluated by the data step compiler when the data step is built from your code, so it cannot be executed conditionally (it is in fact never executed).

OUTPUT, OTOH, is an executable statement which can be used conditionally (as is the fact in your code). It writes an observation to the output dataset.

If no OUTPUT is coded by you, the data step compiler will insert one on its own at the very end of the data step, so for every completed data step iteration an observation is written.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 454 views
  • 0 likes
  • 3 in conversation