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

What does it mean when an if statement is only followed by the name of a library?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

As a new user, it's understandable that you wouldn't understand:

 

IF FIRST.SHORT_ACCOUNT_NUMBER;

 

It's actually more complicated than it looks, so I can give you the overview only.

 

IF deletes observations, and continues to process other observations.  The ones that satisfy the IF condition continue to be processed, and the others get deleted.

 

FIRST.SHORT_ACCOUNT_NUMBER is created in a DATA step using a BY statement.  What it does, and how it works, will take some study on your part.  (You have already been pointed to some reference material.)

 

The net result in this program handles cases where there are multiple observations for the same SHORT_ACCOUNT_NUMBER:

 

  • Just keep the first observation for each SHORT_ACCOUNT_NUMBER
  • Delete any remaining observations for the same SHORT_ACCOUNT_NUMBER

Hope this at least points you in the right direction.

View solution in original post

5 REPLIES 5
LinusH
Tourmaline | Level 20

You mean "name of a variable"?

 

If that's the case, you are referring to a "subsetting if". It means that any observation that does meet the criteria, is not processed further on in the data step. So any explicit or implicit output will not be performed.

 

If you just name a variable, for a numerical value of 0 means false (subset will occur), any other value is evaluated as true (processing will proceed with the following steps).

 

Do you have an example?

Try to execute it, evaluate the results. Potentially change input data/IF statement and see the differences.

Data never sleeps
hled683
Calcite | Level 5

for example:

DATA CR_OPEN_IO_PART_TEMP_1;

SET CR_OPEN_IO_PART_TEMP;

BY SHORT_ACCOUNT_NUMBER;

IF FIRST.SHORT_ACCOUNT_NUMBER;

RUN;

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

The by statement:

BY SHORT_ACCOUNT_NUMBER;

Creates a binary value, 1 for true, 0 for false, which is set based on whether a value is the first occurrence of a value in that variable.  A bit like:

SHORT_ACCOUNT_NUMBER      ISFIRST

A                                               1

A                                               0

...

 

The if:

IF FIRST.SHORT_ACCOUNT_NUMBER;

Is the same as saying: if isfirst=1 then output;

 

Please dont code all in uppercase, it makes code painful to read.

Astounding
PROC Star

As a new user, it's understandable that you wouldn't understand:

 

IF FIRST.SHORT_ACCOUNT_NUMBER;

 

It's actually more complicated than it looks, so I can give you the overview only.

 

IF deletes observations, and continues to process other observations.  The ones that satisfy the IF condition continue to be processed, and the others get deleted.

 

FIRST.SHORT_ACCOUNT_NUMBER is created in a DATA step using a BY statement.  What it does, and how it works, will take some study on your part.  (You have already been pointed to some reference material.)

 

The net result in this program handles cases where there are multiple observations for the same SHORT_ACCOUNT_NUMBER:

 

  • Just keep the first observation for each SHORT_ACCOUNT_NUMBER
  • Delete any remaining observations for the same SHORT_ACCOUNT_NUMBER

Hope this at least points you in the right direction.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 881 views
  • 2 likes
  • 5 in conversation