call symput ("<>", < >)
symput
procedure is the name of the macro variable, which must be assigned the value of the second argument.data _null_;
count=1978;
call symput('count',count);
run;
%put &count;
19 data _null_;
20 count=1978;
21 call symput('count',count);
22 run;
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
21:21
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
23 %put &count;
1978
count
was defined as 1978, SAS issued a remark sayingNOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
21:21
data _null_;
count=1978;
call symput('count',strip(put(count,8.)));
run;
%put &count;
29 data _null_;
30 count=1978;
31 call symput('count',left(put(count,8.)));
32 run;
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
33 %put &count;
1978
CALL SYMPUT
, this macro variable can not be used directly in the same datastep. The reason for this phenomenon is that the macro code is compiled and executed before the datastep is compiled and executed. So, the macro variable created by CALL SYMPUT
will not be available in the datastep due to the fact that this macro variable will be created and assigned only after or during the execution of the datastep code.RESOLVE
or SYMGET
)CALL SYMPUT
procedure is used outside of a macro (that is, in open source), it creates a global macro variable, whereas when used inside a macro, it creates a local one.CALL SYMPUTX
was announced by SAS in version 9 in order to bypass the CALL SYMPUT
traps.CALL SYMPUTX
over CALL SYMPUT
include:SYMPUTX
automatically converts numeric variables to character variables before assigning them to a macro variable. (You no longer need to manually convert with the aid of PUT as in the example above)CALL SYMPUTX
removes leading and trailing spaces. So the need for functions, like STRIP
or LEFT
, to clear extra spaces, is no longer necessary.call symputx ("<>", < >, < >)
CALL SYMPUT
arguments. The third argument (symbol table) is optional and can be G, L or F. If you specify G, a macro variable will be created in the global symbol table, but if you specify L, SAS saves the macro variable in the local table. If the third argument is not specified or set to F, CALL SYMPUTX
will behave similarly to CALL SYMPUT
.data _null_;
count=1978;
call symputx('count',count,'G');
run;
%put &count;
29 data _null_;
30 count=1978;
31 call symputx('count',count,'G');
32 run;
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
33 %put &count;
1978
CALL SYMPUT
instead of CALL SYMPUTX
, the program would run identically, but a note would be issued to the log about automatic conversion of a numerical value to a character value.CALL SYMPUT
and CALL SYMPUTX
:call symput('macrovar', trim(left(charvar)));
call symputx('macrovar', charvar);
Source: https://habr.com/ru/post/142147/
All Articles