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,

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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