楼主: chenys625
6310 13

面试时被问到的一个双set的问题 [推广有奖]

  • 0关注
  • 2粉丝

已卖:156份资源

硕士生

34%

还不是VIP/贵宾

-

威望
0
论坛币
53 个
通用积分
0
学术水平
32 点
热心指数
29 点
信用等级
26 点
经验
2400 点
帖子
176
精华
0
在线时间
123 小时
注册时间
2012-1-17
最后登录
2019-11-25

楼主
chenys625 发表于 2012-8-14 14:09:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
面试问题如下:set a b; 与 set a; set b; 都会有怎样的效果?

回答:
set a b; 就是纵向的拼接,如果有不同的变量,那相应位置就是空值。

set a; set b; 当时就有点虚,后来在群里跟sas兄弟讨论后得到答案如下:
变量数是A B 两个的总和,观测数是A,B中观测最少的那个。原理是 SET A B 一个指针一个pdv;set a;set b 两个指针,一个pdv。a的指针将数据集a的第一条观测读入PDV,b的指针将b的第一条观测读入pdv,然后输出,返回data步开头。以此类推。
比如a的观测少,a的指针先指向数据集a的末尾,由于a的指针已指向数据集a的末尾,固跳出data步。如果加上output还有一些结论,试一下很好理解了。


以下是测试的程序:
data a;
do a=1 to 10 by 2;
output;
end;
run;

data b;
do b=2 to 14 by 2;
output;
end;
run;

data c;
set a;
set b;
output; /*在此无影响*/
run;

data c;
set a;
output; /*b第一个观测为空,b的观测整体往下错了一位*/
set b;
run;

/*b第一个观测为空,a、b每个观测重复两遍(b第一个除外)*/
data c;
set a;
output;
set b;
output;
run;

以上是讨论结果,感谢指点我的兄弟!

二维码

扫码加我 拉你入群

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

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

关键词:Set output outpu data步 Data 面试

回帖推荐

bobguy 发表于2楼  查看完整内容

There are many more combination of set usages. It really depends how much one is understanding. Here is an example to have all observations output. data t1; do i=1 to 5; x=i; output; end; run; data t2; do y=1 to 12; z=y; output; end; run; data t3; if _n_
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
oliyiyi + 1 + 1 + 1 精彩帖子

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

本帖被以下文库推荐

沙发
bobguy 发表于 2012-8-15 10:20:01
There are many more combination of set usages. It really depends how much one is understanding.

Here is an example to have all observations output.

data t1;
   do i=1 to 5;
      x=i;
          output;
        end;
run;

data t2;
   do y=1 to 12;
      z=y;
          output;
        end;
run;

data t3;
  if _n_<=nobs then set t1 nobs=nobs;
  set t2;
  run;

  proc print;run;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

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

藤椅
suzhzh 发表于 2012-8-15 10:30:27
Thanks so much for this explicit explanation.

板凳
chenys625 发表于 2012-8-15 11:13:15
bobguy 发表于 2012-8-15 10:20
There are many more combination of set usages. It really depends how much one is understanding.

H ...
set前加 if 之前确实没遇到过,琢磨一下启发很大! 非常感谢

报纸
flutter88 发表于 2012-8-15 19:13:26
很早之前也实验过,但是在实际工作中从来没使用这种用法

地板
流光速1991 发表于 2012-8-15 19:18:14
看看呀

7
chenys625 发表于 2012-8-15 20:05:22
flutter88 发表于 2012-8-15 19:13
很早之前也实验过,但是在实际工作中从来没使用这种用法
是啊兄弟 我平时也从来没用过 结果面试一问就虚了 呵呵~ 感觉确实没什么用

8
lynette_89 发表于 2012-8-15 21:58:23
恩,关于拼接的问题,base里chapter 13有

9
chenys625 发表于 2012-8-15 22:00:39
lynette_89 发表于 2012-8-15 21:58
恩,关于拼接的问题,base里chapter 13有
噢 没有完整的看过教材 有空去学习下 thanks

10
lynette_89 发表于 2012-8-18 23:21:21
呵呵 么四么四   祝你成功

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

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