全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3644 5
2013-10-09
Q17:
Given the SAS data set ONE:
ONE
DIVISION SALES
A              1234
A              3654
B              5678
The following SAS program is submitted;
Data _null_;
Set one;
By division;
If first.division then
Do;
%let mfirst=sales;
end;
run;
What is the value of the macro variable MFIRST when the program finishes
execution?
A. 1234
B. sales
C. 5678
D. null
我用程序跑过,确实是B. 但为什么不是C呢,想不明白。

Q80:
The following SAS program is submitted:
%let rc=Begin;
%macro test;
data out;
set sashelp.prdsale nobs = totalobs;
if totalobs > 10 then do;
%let rc = high;
end;
else do;
%let rc = low;
end;
run;
%mend;
%let rc = Before Execution;
%test
The data set SASHELP.PRDSALE has 50 observations.
What is the value of the variable RC when the macro finishes execution?
A. low
B. high
C. Begin
D. Before Execution
答案是A,我认为是B。想不明白。



二维码

扫码加我 拉你入群

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

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

全部回复
2013-10-10 17:16:25
第一题,使用%let语句的时候就是纯文本赋值,如果想要给他变量的真实值,可以用回调函数

data a;
        input division $1. sales 8.;
        datalines;
A 1234
A 3654
B 5678
;
run;

Data _null_;
        Set A;
        By division;
        If first.division then
        Do;
        %let mfirst=sales;
        end;
run;

%put &mfirst;

Data _null_;
        Set A;
        By division;
        If first.division then Do;
                call symputx('mfirst',sales);
        end;
run;

%put &mfirst;
二维码

扫码加我 拉你入群

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

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

2013-10-10 17:30:07
第二题,应该是宏和data步处理时间的不同,具体原因记不清了,我想可能是if else语句不能限制宏命令编译期间的运行。所以最后是low

%let rc=Begin;
%macro test;
        data out;
                set sashelp.prdsale nobs = totalobs;
                a = totalobs;
                if totalobs > 10 then do;
                        b = 1;
                        %let rc = high;
                end;else do;
                        c = 1;
                        %let rc = low;
                end;

        run;
%mend;
%let rc = Before Execution;
%test;

%put &rc.;
二维码

扫码加我 拉你入群

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

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

2013-10-10 20:10:00
第二题, rc的赋值是在处理宏的时候进行的, 在运行宏生成的代码时其实%let 这句代码已经不存在了。这里的if else不起任何作用, 除非换成%if 和%else.
二维码

扫码加我 拉你入群

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

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

2013-10-10 23:32:39
多谢帮助!
二维码

扫码加我 拉你入群

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

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

2015-8-8 02:01:32
chendonghui1987 发表于 2013-10-10 17:16
第一题,使用%let语句的时候就是纯文本赋值,如果想要给他变量的真实值,可以用回调函数

data a;
为什么结果不是first。division =1234??
怎样才能得到first.division=1234呢
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群