***Macro variable scope example; %LET globalvar=This is a global variable; %PUT &globalvar; %MACRO scope_example; %LET local_var=This is a local variable; %PUT &local_var; %MEND; %scope_example; %PUT &local_var; %MACRO make_global; %GLOBAL now_global; %LET now_global=I am now a global variable; %PUT &now_global; %MEND; %make_global; %PUT &now_global; ***sashelp.vmacro example; DATA day_vars; SET sashelp.vmacro; WHERE name LIKE 'SYSDA%'; RUN; ***Macro special functions; %LET cities=Melbourne&Sydney; %LET cities=Melbourne%STR(&)Syndey; %PUT &cities; %LET x=10; %PUT &x+5; %PUT %EVAL(&x+5); ***Determine whether macro functions exist; PROC CATALOG CATALOG=work.sasmacr; CONTENTS OUT=mymacros; RUN; QUIT; PROC SQL; CREATE TABLE mymacros AS SELECT * FROM dictionary.catalogs WHERE memname='SASMACR'; QUIT; /* setup data*/ data testdata; format id $10.; format desc $100.; id = '1'; desc='hello world'; output; run; /* create macro variables - sql */ proc sql; select desc into : var_descA from testdata where id eq '1'; quit; /* create macro variables - data _null_ */ data _null_; set testdata; where id eq '1'; call symput('var_descB', desc); call symputx('var_descX', desc); run; /* display values - with whitespace */ %put |&var_descA.|; %put |&var_descB.|; %put |&var_descX.|; /* removes whitespace */ %let var_descA = &var_descA.; %let var_descB = &var_descB.; /* display values - no whitespace */ %put |&var_descA.|; %put |&var_descB.|; %put |&var_descX.|;