楼主: 一眼瞬间
9146 3

[原创博文] proc sql distinct把我给弄晕了,大家能看下不? [推广有奖]

  • 0关注
  • 1粉丝

讲师

50%

还不是VIP/贵宾

-

威望
0
论坛币
730 个
通用积分
0.0001
学术水平
0 点
热心指数
4 点
信用等级
0 点
经验
903 点
帖子
376
精华
0
在线时间
309 小时
注册时间
2010-3-14
最后登录
2023-8-19

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
这样一段程序,不理解distinct的意思。主要是第一段sql不明白,run了一下,但是我不知道为什么用了这个,“
select distinct
        a.symbol,
        b.value,
        year(a.date)
as year,
        b.date as date5
    from
        one a,
        one b
    where
            a.symbol=b.symbol
        and intck('year',b.date,a.date) between 1
and
5

就变成了
                                         The SAS System      

                         Obs    symbol     value     year        date5

                           1     ABP1     -0.0250    1998    18FEB1997
                           2     ABP1     -0.0250    1999    18FEB1997
                           3     ABP1      0.0500    1999    25FEB1998
                           4     ABP1     -0.0250    2000    18FEB1997
                           5     ABP1      0.0500    2000    25FEB1998
                           6     ABP1     -0.0250    2000    05MAR1999
                           7     ABP1     -0.0250    2001    18FEB1997
                           8     ABP1      0.0500    2001    25FEB1998
                           9     ABP1     -0.0250    2001    05MAR1999
                          10     ABP1      0.0600    2001    20MAR2000
                          11     ABP1     -0.0250    2002    18FEB1997
                          12     ABP1      0.0500    2002    25FEB1998
                          13     ABP1     -0.0250    2002    05MAR1999
                          14     ABP1      0.0600    2002    20MAR2000
                          15     ABP1      0.2500    2002    05MAR2001
                          16     ABP1      0.0500    2003    25FEB1998
                          17     ABP1     -0.0250    2003    05MAR1999
                          18     ABP1      0.0600    2003    20MAR2000
                          19     ABP1      0.2500    2003    05MAR2001
                          20     ABP1      0.4550    2003    07MAR2002
                          21     ABP1     -0.0250    2004    05MAR1999
                          22     ABP1      0.0600    2004    20MAR2000
                          23     ABP1      0.2500    2004    05MAR2001
                          24     ABP1      0.4550    2004    07MAR2002
                          25     ABP1      0.7300    2004    25FEB2003
                          26     ABP1      0.0600    2005    20MAR2000
                          27     ABP1      0.2500    2005    05MAR2001
                          28     ABP1      0.4550    2005    07MAR2002
                          29     ABP1      0.7300    2005    25FEB2003
                          30     ABP1      1.0100    2005    19FEB2004
                          31     ABP1      0.2500    2006    05MAR2001
                          32     ABP1      0.4550    2006    07MAR2002
                          33     ABP1      0.7300    2006    25FEB2003
                          34     ABP1      1.0100    2006    19FEB2004
                          35     ABP1      1.2500    2006    16FEB2005
                          36     ABP1      0.4550    2007    07MAR2002
                          37     ABP1      0.7300    2007    25FEB2003
                          38     ABP1      1.0100    2007    19FEB2004
                          39     ABP1      1.2500    2007    16FEB2005
                          40     ABP1      1.6500    2007    09FEB2006
                          41     ABT       0.5550    1992    14JAN1991
                          42     ABT       0.5550    1993    14JAN1991
                          43     ABT       0.6375    1993    14JAN1992
到底distinct是什么意思呢?先谢谢了!

/* test data */
data one;
  input symbol $ value date :date9.;
  format date date9.;
cards;
ABP1 -0.025
18feb1997
ABP1  0.05
25feb1998
ABP1 -0.025
05mar1999
ABP1  0.06
20mar2000
ABP1  0.25
05mar2001
ABP1  0.455
07mar2002
ABP1  0.73
25feb2003
ABP1  1.01
19feb2004
ABP1  1.25
16feb2005
ABP1  1.65
09feb2006
ABP1  1.87
08feb2007
ABT   0.555
14jan1991
ABT   0.6375
14jan1992
ABT   0.73
16jan1993
;
run;

proc sql;
    create table two as
select distinct
        a.symbol,
        b.value,
        year(a.date)
as year,
        b.date as date5
    from
        one a,
        one b
    where
            a.symbol=b.symbol
        and intck('year',b.date,a.date) between 1
and
5
    order by
        a.symbol,
        year,
        date5;
quit;

proc sql;
    create table three as
select distinct
        symbol,
        year,
        count(symbol)
as n5,
        avg(value)
as avg5,
        std(value)
as std5
    from
        two
    group
by
        symbol,
        year;
quit;
二维码

扫码加我 拉你入群

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

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

关键词:proc sql Distinct Dis Inc IST

回帖推荐

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

Distinct 的作用就是去除重复记录的。 You can eliminate the duplicate rows from the results by using the DISTINCT keyword in the SELECT clause. data test; input value; cards; 1 2 1 2 3 2 1 2 3 3 3 ; proc sql; create table test1 as select distinct value from test; quit; proc print;run;

本帖被以下文库推荐

沙发
pobel 在职认证  发表于 2010-11-6 08:33:01 |只看作者 |坛友微信交流群
Distinct 的作用就是去除重复记录的。
You can eliminate the duplicate rows from the results by using the DISTINCT keyword in the SELECT clause.

data test;
    input value;
        cards;
1
2
1
2
3
2
1
2
3
3
3
;

proc sql;
     create table test1 as
           select distinct value from test;
quit;

proc print;run;
和谐拯救危机

使用道具

藤椅
liudeng2005 发表于 2010-11-6 20:46:09 |只看作者 |坛友微信交流群
a Cartesian Product is created when using full join ,so for your data,14*14 rows are generated,then rows that are duplicate will be deleted(here duplicationg means values of all variables are the same) based on the on clause.
我就是我@!

使用道具

板凳
一眼瞬间 发表于 2010-11-7 07:14:10 |只看作者 |坛友微信交流群
谢谢LS两位!

使用道具

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

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

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

GMT+8, 2024-4-30 23:08