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

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

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
Reeza
Super User
COUNT+1 increments the count variable by 1. It's documented under the SUM statement.
https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lestmtsref&docsetTarget=n...

Regarding your second question, I think you're mixing up the _error_ variable which is an automatic SAS variable. error in this case is a variable in the data set and the logic depends on context and needs.
mava
Obsidian | Level 7
Thanks!!!!
Tom
Super User Tom
Super User

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'.

 

mava
Obsidian | Level 7
Thank u
mava
Obsidian | Level 7
Thank u so much!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1704 views
  • 0 likes
  • 3 in conversation