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!

sas-innovate-2024.png

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.

 

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