BookmarkSubscribeRSS Feed
Jianan_luna
Obsidian | Level 7

I am currently studying SAS Macro Language 1 essentials course. When I was doing level 2 practice under 3.4 indirect references to macro variables.  For question 3, I am confused the answer, "&&&code", why don't use "&&countrycode&code"? Thanks so much. And what does &&&code stand for?

 
 

Annotation 2020-08-21 181308.png

1 REPLY 1
Cynthia_sas
Diamond | Level 26

Hi:

  You did not create numbered variables. That is why you don't have &&country&code.

 

  Please go back and watch the video on macro variable resolution. In particular the forward scan rule and the rescan rule:

Cynthia_sas_0-1598056776358.png

 

  After your first DATA _NULL_ step, you can insert a %PUT _USER_ and then in the LOG you'll see that the country 2 character code is the macro variable, as shown below:

Cynthia_sas_1-1598056418059.png

 

So if you want to have the macro variable resolve to Luxembourg for the TITLE, you need to use &LU or some reference that will end up turning into &LU and then Luxembourg. And if you wanted it to appear as United Kingdom, you'd need to use &GB.

 

But, the WHERE statement needs to use the 2 character code to select the rows you want That's where &code comes in. For the WHERE statement to work, you need to be able to pass in the string "LU" or "IT" or "GB" -- but then, as long as you have that string and you can use that string for a macro variable, then indirect references allows &&&code to turn into &LU and to then resolve to Luxembourg for the title.

Hope that makes sense,

Cynthia