楼主: greeny82
3691 5

[问答] 求教2道sas advance题目。 [推广有奖]

  • 0关注
  • 0粉丝

初中生

42%

还不是VIP/贵宾

-

威望
0
论坛币
8 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
122 点
帖子
5
精华
0
在线时间
25 小时
注册时间
2013-6-3
最后登录
2017-5-9

楼主
greeny82 发表于 2013-10-9 22:20:37 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
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。想不明白。



二维码

扫码加我 拉你入群

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

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

关键词:ADVANCE VANCE advan ance NCE execution following null 程序

沙发
chendonghui1987 发表于 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;

藤椅
chendonghui1987 发表于 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.;

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

报纸
greeny82 发表于 2013-10-10 23:32:39
多谢帮助!

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

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

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 14:16