BookmarkSubscribeRSS Feed
Nietzsche
Lapis Lazuli | Level 10

In the SAS Programming 2 course, the solution is

if first.Product then TotalProfit=0;

but in the instruction, where was all done with first.variable = 1 or last.variable = 1. Why was it omitted in this cause? Is it because =1 means True and "if first.product " statement means if True as well?

Nietzche_0-1666428755997.png

 

also why is  the last.product have a =1 after it?

Is it because if you have a if/then statement you don't need the =1, but you use only the IF statement, you will need to put the =1?

Nietzche_0-1666429652434.png

 

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
5 REPLIES 5
Astounding
PROC Star

The =1 is not needed because SAS automaticaly evaluates 1 as "true" and 0 as "false".  Actually, SAS evaluates any numeric value.  0 and missing values are considered to be false.  Any other value (including negative numbers) is considered to be true.

Kurt_Bremser
Super User

Boolean variables created by SAS (like the FIRST. and LAST., but also those defined with IN= or END= options) can only take on values of 0 and 1, which means false and true, respectively, and can be used as a Boolean value on their own.

Tom
Super User Tom
Super User

The two expressions are equivalent.  The first more clearly shows the INTENT of the programmer.  The intent is to test if the flag is TRUE or FALSE.

 

SAS only has two type of variables.  Fixed length character strings and floating point numbers.

 

SAS will treat a numeric value of 0 or missing as FALSE and any other value as TRUE when performing a boolean test, such as in your first example code.  SAS will generate 0 for true and 1 for FALSE as the result of any boolean operator.  So boolean flags created by SAS such as FIRST. and LAST. will be either 0 or 1.  You can treat them as boolean values (if first.product) or treat them as numbers (if last.product=1).

Nietzsche
Lapis Lazuli | Level 10

 


@Tom wrote:

 

SAS will treat a numeric value of 0 or missing as FALSE and any other value as TRUE when performing a boolean test, such as in your first example code.  SAS will generate 0 for true and 1 for FALSE as the result of any boolean operator.  So boolean flags created by SAS such as FIRST. and LAST. will be either 0 or 1.  You can treat them as boolean values (if first.product) or treat them as numbers (if last.product=1).


is this a typo? 0 for TRUE 1 for FALSE?

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 379 views
  • 3 likes
  • 4 in conversation