Hi. I am studying for the base certification exam from the 5th edition of the Base Cert Prep book.
I have a question about these examples that are in the book and I do not understand that the
1. count+1 is counting
2. why an error=1 is in the statement
I understand the conditions, though - just not those 2 statements.
Here are the codes for the 2 examples in which I am confused.
I highlighted what I do not understand in blue.
Example 1:
if status='OK' and type=3
then count+1; (Does this count the number of type with the value 3? )
if (age ne agecheck or time ne3) and error=1 then Test=1; (why is error=1 in there? I thought that was if there was at least one error in the program.
Question: What does the example 1 program?
Example 2:
if (age ne agecheck or time ne 3)
and error=1 then Test=1; ( I don't understand why the error=1 is in there)
if status='S' or cond='E'
then Control='Stop'; (I don't understand this one at all or am confused)
What does the example 2 program? What is it doing?
Thank you! Mava
Both of these are just snippets of code. Not a full program. Or even a full data step.
What the meaning of the statements is depends on the context they are used in. Including the data step they are running in.
In SAS the = is used for equality testing in boolean expressions (type=3) and in assignment statements (CONTROL='Stop'). The SAS compiler knows which you mean by the larger context of how you used them.
Your code snippets have three types of statements being used.
IF/THEN statement-> IF condition THEN statement ;
Assignment statement-> variable = expression;
Sum statement-> variable + expression ;
First question:
The IF/THEN statement means the value of COUNT is incremented by 1 when the condition tested is true. So not just when TYPE=3 but also it is chekcing if STATUS='OK'. The fact that you used a SUM statement means that the variable COUNT will be retained across iterations of the data step instead of being reset to missing.
Second/Third question:
In this context ERROR is the name of variable, just like TYPE and STATUS and COUNT in the previous statement. So the meaning of the test ERROR=1 depends on what it means for that variable to have that value.
Last question:
This statement is testing the values of the variable STATUS and COND and then conditionally changing the value of CONTROL to 'Stop'.
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.
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.