BookmarkSubscribeRSS Feed
pri26
Calcite | Level 5

Screen Shot 2020-02-16 at 10.04.39 PM.png

 

Hi,

I don't understand why the answer to this is a and not b?

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

WORD is set when AMOUNT=7.

It is not reset when AMOUNT changes.

ed_sas_member
Meteorite | Level 14

Hi @pri26 

If you execute the code step by step:

  • first, amount is set to 7

Capture d’écran 2020-02-16 à 10.24.54.png

 

 

 

  • Then SAS checks the IF condition:
    • if amount = 5 then word = "CAT"; FALSE
    • else if amount = 7 then word = "DOG"; TRUE -> so the value of word is set to 'DOG'
    • else word = "NoNE !!!"; FALSE

 

Capture d’écran 2020-02-16 à 10.25.10.png

 

 

 

  • Finally, the value of amount is set to 5:

 

Capture d’écran 2020-02-16 à 10.25.19.png

 

 

 

 

NB: it would have been better to have a LENGTH statement to define the word variable. As it is missing here, the length is set by default to 3, as it is the length of the first value proposed for this variable in the IF condition ('CAT'). It doesn't matter here as 'DOG' has the same number of letters than 'CAT'. But you can test to set amount to 3 for example, you will see that the 'ELSE' statement is true and that is displays 'NoN' and not 'NoNE !!!'

 

Best,

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 775 views
  • 1 like
  • 3 in conversation