boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - SAS help : The scope of macro variables
相关主题
SAS Macro 问题请教 。。。
[合集] sas advance question
菜鸟请教关于赋给macro variables变量值
请问如何用一个在macro里的call symput产生global 的macro variable?
一道ADV 130 题目
请教一个macro的问题
SAS ADVANCED 一道题求助
SAS call symput question
请教SAS adv 题库一道macro题
SAS初级问题请教
相关话题的讨论汇总
话题: macro话题: symget话题: variable话题: variables话题: global
进入Statistics版参与讨论
1 (共1页)
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.

相关主题
请问如何用一个在macro里的call symput产生global 的macro variable?
一道ADV 130 题目
请教一个macro的问题
SAS ADVANCED 一道题求助
进入Statistics版参与讨论
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.

1 (共1页)
进入Statistics版参与讨论
相关主题
SAS初级问题请教
请教个macro的问题
急问这个SAS的code该怎么写
一个关于macro的问题,多谢。
急问:SAS batch submission with macro variable
Re: SAS help : How to use Macro to select procedurs
sas 中如何给一个variable 加密?
Help! A data step problem
[合集] 问个SAS的问题
请教一个SAS Macro问题。谢谢
相关话题的讨论汇总
话题: macro话题: symget话题: variable话题: variables话题: global