p***r 发帖数: 920 | 1 Recently, aware many problems when programming macros. The scope of macro
variables (global/local) are sometimes in in-explicit to me. It there any
articles systematically covering this topic.
1. In a macro, if you use SYMPUT in data step, the macro variable you
created is global.
2. If you want to use SYMGET to input the value to the data set, then the
macro variable must be global. Then here is the problem, locally produced
macro variable will disappear, and will not be an valid argument during
the SYMGET function.
These are some of my observations but some references would be very
helpful.
Thx. | l*****8 发帖数: 483 | 2 1. In a macro, if you use SYMPUT in data step, the macro variable you
created is NOT always global.
try the following 2 examples...
%macro prtrost(num=1);
data _null_;
call symput(’today’,trim(left(put(today(),mmddyy10.))));
run;
%mend prtrost;
%prtrost(num=8);
%put _all_; | p***r 发帖数: 920 | 3 this is exactly what i'm talking about. But how to know this?
【在 l*****8 的大作中提到】 : 1. In a macro, if you use SYMPUT in data step, the macro variable you : created is NOT always global. : try the following 2 examples... : %macro prtrost(num=1); : data _null_; : call symput(’today’,trim(left(put(today(),mmddyy10.)))); : run; : %mend prtrost; : %prtrost(num=8); : %put _all_;
| l*****8 发帖数: 483 | 4 第一个已经先有了一个local num, local table 不是空的,所以再用symput,就都是
local.
第二个因为local table是空的,生成得就是globle. | p***r 发帖数: 920 | 5 explain well, where should I go to dig in more
【在 l*****8 的大作中提到】 : 第一个已经先有了一个local num, local table 不是空的,所以再用symput,就都是 : local. : 第二个因为local table是空的,生成得就是globle.
| l*****8 发帖数: 483 | | b*u 发帖数: 30 | 7 Both examples do NOT work in my PC. Can you tell me the reason?
LOG:
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted
string,
a numeric constant, a datetime constant, a missing value,
arrayname, (, ), +,
',', -, INPUT, NOT, OF, PUT, ^, _NEW_, ~.
ERROR 159-185: Null parameters for SYMPUT are invalid.
ERROR 202-322: The option or parameter is not recognized and will be ignored. | p***r 发帖数: 920 | 8 using '', instead of ''in chinese
quoted
ignored.
【在 b*u 的大作中提到】 : Both examples do NOT work in my PC. Can you tell me the reason? : LOG: : ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted : string, : a numeric constant, a datetime constant, a missing value, : arrayname, (, ), +, : ',', -, INPUT, NOT, OF, PUT, ^, _NEW_, ~. : ERROR 159-185: Null parameters for SYMPUT are invalid. : ERROR 202-322: The option or parameter is not recognized and will be ignored.
| p***r 发帖数: 920 | | b*u 发帖数: 30 | 10 Got it. Thanks!
【在 p***r 的大作中提到】 : using '', instead of ''in chinese : : quoted : ignored.
| | | f*****k 发帖数: 110 | 11 It seems the following link is only for prior's first observation.So any
reference for his/her second observation -- "If you want to use SYMGET to
input the value to the data set, then the
macro variable must be global"--? I just feel that it would be convenient if
SYMGET can also use local macro variable even though only under special
conditions. Thanks.
【在 l*****8 的大作中提到】 : http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML : http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML
| p***r 发帖数: 920 | 12 I think symget can only use global macro variables as I tried. And its kinda
of bugging that, using
%let var=;
would only give u a local macro variable, and when the macro is compiled and
the text unwrapped, &var will be deleted and you cannot call it using
symget when executing data step.
I really would like to know more about why and how.
if
【在 f*****k 的大作中提到】 : It seems the following link is only for prior's first observation.So any : reference for his/her second observation -- "If you want to use SYMGET to : input the value to the data set, then the : macro variable must be global"--? I just feel that it would be convenient if : SYMGET can also use local macro variable even though only under special : conditions. Thanks.
| f*****k 发帖数: 110 | 13 What if the data step where SYMGET is used is contained in a macro? There
would be a local table from which SYMGET can get values, I guess.
kinda
and
【在 p***r 的大作中提到】 : I think symget can only use global macro variables as I tried. And its kinda : of bugging that, using : %let var=; : would only give u a local macro variable, and when the macro is compiled and : the text unwrapped, &var will be deleted and you cannot call it using : symget when executing data step. : I really would like to know more about why and how. : : if
| p***r 发帖数: 920 | 14 that's what i was saying, i don't think it can.
【在 f*****k 的大作中提到】 : What if the data step where SYMGET is used is contained in a macro? There : would be a local table from which SYMGET can get values, I guess. : : kinda : and
| f*****k 发帖数: 110 | 15 i am not sure either so I expect an authoritative reference too. If you
happen to get it later, don't forget to send me a message. I will do the
same thing for you.
【在 p***r 的大作中提到】 : that's what i was saying, i don't think it can.
| p***r 发帖数: 920 | 16 you bet
【在 f*****k 的大作中提到】 : i am not sure either so I expect an authoritative reference too. If you : happen to get it later, don't forget to send me a message. I will do the : same thing for you.
|
|