Search code examples
variablessasrefer

Referring to a macro variable already defined


I was going through a SAS code and found the following ways of referencing a macro variable.

  1. &variable_name .
  2. &variable_name

I know that the first way of referencing is the normal way of how we refer to a defined macro variable in sas.

But, could you please explain how does the second way(without period after the macro variable name) is different from the first way


Solution

  • It is the short way to reference a variable. However it makes a difference when concatenating output:

    %let var = My name ;
    
    %put &var.is Paul;
    // Output: My name is Paul.
    
    %put &varis Paul;
    // Output: WARNING: Apparent symbolic reference VARIS not resolved.
    // &varis Paul
    

    Another example where you definitely need a .:

    %let lib = sashelp;
    data temp;
      set &lib..class;
    run;
    

    I would recommend to always use the variant &variable.. Because it is clear where the variable ends.