楼主: njmch
12704 10

请教SAS 宏引用函数 [推广有奖]

  • 0关注
  • 1粉丝

讲师

8%

还不是VIP/贵宾

-

威望
0
论坛币
3 个
通用积分
0
学术水平
1 点
热心指数
2 点
信用等级
0 点
经验
5475 点
帖子
89
精华
0
在线时间
734 小时
注册时间
2006-9-29
最后登录
2022-12-20

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
最近看SAS程序,碰到SAS的宏引用函数,总是弄不明白。

特别是%nrstr, %nrbquote和%superq这三个函数之间的区别。

SAS官网说%nrstr是在compile时mask, %nrbquote是在execute时mask,不清楚是在说什么

请各位帮忙解惑,若有例子最好

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:COMPILE EXECUTE Quote super sas程序 程序

沙发
njmch 发表于 2011-12-10 11:48:35 |只看作者 |坛友微信交流群
SAS帮助文档是这么说的,

  • %QUOTE and %NRQUOTE mask the same items as %STR and %NRSTR, respectively. However, %STR and %NRSTR mask constant text instead of a resolved value.
  • And, %STR and %NRSTR work when a macro compiles, while %QUOTE and %NRQUOTE work when a macro executes.

谁能解释一下第二点究竟是什么意思


使用道具

藤椅
bF7JEsto 发表于 2011-12-11 01:47:42 |只看作者 |坛友微信交流群
有点意思。。。

使用道具

板凳
njmch 发表于 2011-12-11 16:42:59 |只看作者 |坛友微信交流群
The macro language provides an additional set of tools to assist in:
  • communicating between SAS steps,
  • constructing executable and reusable code,
  • designing custom languages,
  • developing user-friendly routines,
  • conditionally execute DATA or PROC steps.

It is worth mentioning that during macro compilation only macro statements are compiled, so be aware that non-macro
text and macro references are not evaluated during the compilation phase – but during macro execution .

When one macro is invoked, the SAS code is generated. This time is called macro execution time.
It is intertwined with the compiling (or parsing) of the generated SAS code. Finally there is the SAS execution time when the compiled code is executed. Thus the are four important times or stages through which the lines of a SAS program with
macros move.
1. Macro compile time
2. Macro execution time
3. SAS compile time
4. SAS execution time
Typically these times are all intertwined and going on, at the same time for different lines (or parts of lines).

%LET NAME=USERFILE.MASTER;
请问各位:这个%let语句是不是也分compile 和 execute两个阶段处理?

使用道具

报纸
jialincau 发表于 2012-11-1 04:39:47 |只看作者 |坛友微信交流群
受教了,谢谢!

使用道具

地板
rczj2102 发表于 2014-12-28 11:09:08 |只看作者 |坛友微信交流群
同问啊。。。所以这个帖没有答案么。。。

使用道具

7
Tigflanker 发表于 2014-12-28 14:10:23 |只看作者 |坛友微信交流群
编译/执行问题还好说些,个人感觉Quote族函数的辨用算是SAS Base中最难的了。

推荐本贴:https://bbs.pinggu.org/thread-3111084-1-1.html

仅在宏范围讨论,我举如下一个小例子:(如有理解不对,还请不吝指出)

  1. %symdel x / nowarn;

  2. %put %sysfunc(ifc(%symexist(x), &x., X not exist.));  
  3. * IFC function occur warning when compilation phase, but success when execute phase.;

  4. %put %sysfunc(ifc(%symexist(x), %nrstr(&x.), X not exist.));  
  5. * Both compilation and execute are OK! NRSTR function throw a death string to IFC function.;
复制代码

使用道具

8
jl60156 发表于 2014-12-29 09:43:24 |只看作者 |坛友微信交流群
%nrstr is compile time quoting  function.
%nrbquote  and %superq are execution time quoting  functions.
%superq is the most stringent execution time quoting function. It usually uses the macro variable name as its argument.  if you use & in the argument, it will resolve further as shown in the examples z1 and z2.  The following are the examples including %nrstr and %nrbquote.

%let string1=test;
%let var1=string1;
%let x=%nrstr(&var1);
%let y=%nrbquote(&var1);
%let z1=%superq(&var1);
%let z2=%superq(var1);


         %put &x;
&var1
         %put &y;
string1
         %put &z1;
test
         %put &z2;
string1

已有 2 人评分经验 论坛币 收起 理由
eijuhz + 40 精彩帖子
admin_kefu + 50 精彩帖子

总评分: 经验 + 40  论坛币 + 50   查看全部评分

使用道具

9
Tigflanker 发表于 2014-12-29 11:25:56 |只看作者 |坛友微信交流群
njmch 发表于 2011-12-11 16:42
The macro language provides an additional set of tools to assist in:
  • communicating between S ...
  • 好像在宏范围内,function是有编译的、独立的,例如一个ifc function,就有一个明显编译再执行的过程。

    %let直接赋值,如果右边没有function,那就是个直接执行的action。

    使用道具

    10
    lqyrendajinji 发表于 2014-12-31 07:15:48 |只看作者 |坛友微信交流群
    xuexi xuexi

    使用道具

    您需要登录后才可以回帖 登录 | 我要注册

    本版微信群
    加好友,备注cda
    拉您进交流群

    京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

    GMT+8, 2024-5-11 06:41