/* Way One */
%let x=5; %let y=test; %put &x &y;
/* Mode two */
Data _null_; Call Symput (' x ', 5);
Call Symput (' y ', ' test ');
Run %put &x &y;
/* Mode three */* if there are multiple records, only the value of the first bar */
Proc SQL Noprint;
Select min (weight), max (weight) Into:minw,:maxw
From Sashelp.class;
Quit %put &MINW &maxw;
/* Create more than one macro variable and assign a value that is not created if the range of records is exceeded */
Proc SQL Noprint;
Select name, Age INTO:NAME1-: Name99999999,:age1-: age99999999 from Sashelp.class;
Quit
%put &sqlobs;
%put &name1 &age1;
%put &name2 &age2;
%put &&name&sqlobs &&age&sqlobs;
%put &name100 &age100;/* These two macro variables are not created, the execution will be reported warning*/*/* stitching field values, assigned to a macro variable */proc SQL Noprint inobs=5; Select name Into:names separated by ', ' from Sashelp.class; Quit
%put names=&names;
The difference between the three methods is: 1. %let xxx=yyy; /*%let statements define macro variables almost anywhere in the program */
2. Call symput (' xxx ', ' yyy '); /* can only be defined in date step, the macro variable defined by call Symput in the macro function may be used out of the function;
3. Select XXX into:yyy. /* can only be defined in proc SQL */
%let and Select into these 2 methods generated in the macro function is a local macro variable, if you want to use the macro function, you need to declare the variable type in advance with%global.