楼主: reolin
2427 11

求教sas数据汇总问题 [推广有奖]

  • 0关注
  • 0粉丝

硕士生

69%

还不是VIP/贵宾

-

威望
0
论坛币
2267 个
通用积分
0.0600
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
2086 点
帖子
125
精华
0
在线时间
168 小时
注册时间
2008-11-28
最后登录
2022-7-29

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
有这么一组数据,
customer_nocard_no
100002
100003
100006
100008
200005
200012
300015
400020

我现在要分别汇总customer_no=1、2、3、4客户所拥有的卡数,请问该怎么做?
附:我用if first.customer_no then cardsum=0; cardsum=cardsum+1;的做法显示说我未初始化first.customer_no.
然后我就用proc sql来做,这是我的代码
proc sql;
create table count as
select count(distinct customer_no) as customer
  from a1
  ;
  quit;
但还是做不出正确答案。
二维码

扫码加我 拉你入群

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

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

关键词:总问题 Customer proc sql Distinct custom 汇总 数据 求教

回帖推荐

jingju11 发表于8楼  查看完整内容

6# reolin 你需要加上by ×××;那个x = x+1;可以直接写成x+1;即可。本质上还是把by statement给漏了

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

data have; input customer_no $ card_no$; cards; 1 00002 1 00003 1 00006 1 00008 2 00005 2 00012 3 00015 4 00020 ; run; data wanted; set have; by customer_no; retain cardnum; if first.customer_no then cardnum=0; cardnum+1; if last.customer_no; keep customer_no cardnum; run;

本帖被以下文库推荐

沙发
pobel 在职认证  发表于 2010-7-22 12:04:50 |只看作者 |坛友微信交流群
proc sql;
create table count as
select count(distinct customer_no) as customer
  from a1
group by customer_no
  ;
  quit;
和谐拯救危机

使用道具

藤椅
wkn1986 发表于 2010-7-22 12:05:09 |只看作者 |坛友微信交流群
data wkn;
input customer_no $ card_no$;
cards;
1 00002
1 00003
1 00006
1 00008
2 00005
2 00012
3 00015
4 00020
;
run;
proc sql;
create table wkn1 as
select customer_no,count(*) as cardsum
from wkn
group by customer_no;
quit;
试试看

使用道具

板凳
jingju11 发表于 2010-7-22 12:10:37 |只看作者 |坛友微信交流群
2# pobel
哈哈。我猜,结果都是1吧。

使用道具

报纸
pobel 在职认证  发表于 2010-7-22 12:24:13 |只看作者 |坛友微信交流群
jingju11 发表于 2010-7-22 12:10
2# pobel
哈哈。我猜,结果都是1吧。
马虎了

proc sql;
create table count as
select distinct customer_no ,   count(distinct card_no) as cardnum
  from a1
group by customer_no
  ;
  quit;
已有 1 人评分学术水平 热心指数 收起 理由
reolin + 1 + 1 解决问题

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

和谐拯救危机

使用道具

地板
reolin 发表于 2010-7-22 12:46:25 |只看作者 |坛友微信交流群
那我第一种方法可否做的出来?

使用道具

7
pobel 在职认证  发表于 2010-7-22 12:56:17 |只看作者 |坛友微信交流群
data have;
input customer_no $ card_no$;
cards;
1 00002
1 00003
1 00006
1 00008
2 00005
2 00012
3 00015
4 00020
;
run;

data wanted;
    set have;
        by customer_no;
        retain cardnum;
        if first.customer_no then cardnum=0;
        cardnum+1;
        if last.customer_no;
        keep customer_no cardnum;
run;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

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

和谐拯救危机

使用道具

8
jingju11 发表于 2010-7-22 13:00:24 |只看作者 |坛友微信交流群
6# reolin

你需要加上by ×××;那个x = x+1;可以直接写成x+1;即可。本质上还是把by statement给漏了
已有 1 人评分学术水平 热心指数 收起 理由
reolin + 1 + 1 解决问题

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

使用道具

9
moonstarpursuit 发表于 2010-7-22 14:07:15 |只看作者 |坛友微信交流群
proc sql;
        select distinct customer_no,count(*)
        from a1
        group by customer_no;
quit;

proc sort data=a1;
        by customer_no;
run;

data a2;
        set a1;
        by customer_no;
        if first.customer_no then count=1;
        else count+1;
run;

data a2;
        retain count;
        length count;
        set a1;
        by customer_no;
        if first.customer_no then count=1;
        else count=count+1;
run;

使用道具

10
reolin 发表于 2010-7-22 14:58:24 |只看作者 |坛友微信交流群
谢谢各位高手,尤其是pobel和jingju11 !

使用道具

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

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

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

GMT+8, 2024-5-1 08:25