楼主: georgiagh
7553 11

sas对数据集合并的问题 [推广有奖]

11
lvjinghui 发表于 2009-12-10 15:14:12
data a;
   infile datalines truncover scanover ;
   input index code year x1 x2 x3 ;
   cards;
   102003         10         2003        1           2         3               
   102003         10         2003        2           2         3      
   102004         10         2004        1           4         5
   102005         10         2005        2           4         5
   102006         10         2006        1           6         7
   102006         10         2006        2           7         8
   122003         12         2003        1           8         9
   122004         12         2004        2           9        10
   122005         12         2005        1          10       11
   122005         12         2005        2          10       11
   122006         12         2006        1          11       12
   142004         14         2004        1          12       13
   142005         14         2005        2          13       14
   162005         16         2005        1          14       15
   162006         16         2006        2          15       16
;
run;
proc sort data=a;
   by index   x1;
run;
data a;
  set a;
      by index   x1;
       if first.index;
run;
data b;
  infile datalines truncover scanover;
  input index code year y1 y2 y3;
  cards;
  102003           10         2003       1       2       3
  102004           10         2004       2       3       4
  102005           10         2005       3       4       5
  102006           10         2006       4       5       6
  122003           12         2003       5       6       7
  122004           12         2004       6       7       8
  122005           12         2005       7       8       9
  122006           12         2006       8       9       10
  152004           15         2004       1       2       3
  162004           16         2004       2       3       4
  172005           17         2005       3       4       5
;
run;
proc sort data=a;
     by index code year;
run;
proc sort data=b;
    by index code year;
run;
data c;
    merge a b;
    by index code year;
run;
proc sql noprint;
    create table d as
    select  c.*,count(code) as count
        from c
        group by code        
     ;
quit;
data d;
   set d;
     where count=4;
           keep index code year x1 x2 x3 y1 y2 y3;
run;

12
lvjinghui 发表于 2009-12-10 15:14:50
data a;
   infile datalines truncover scanover ;
   input index code year x1 x2 x3 ;
   cards;
   102003         10         2003        1           2         3               
   102003         10         2003        2           2         3      
   102004         10         2004        1           4         5
   102005         10         2005        2           4         5
   102006         10         2006        1           6         7
   102006         10         2006        2           7         8
   122003         12         2003        1           8         9
   122004         12         2004        2           9        10
   122005         12         2005        1          10       11
   122005         12         2005        2          10       11
   122006         12         2006        1          11       12
   142004         14         2004        1          12       13
   142005         14         2005        2          13       14
   162005         16         2005        1          14       15
   162006         16         2006        2          15       16
;
run;
proc sort data=a;
   by index   x1;
run;
data a;
  set a;
      by index   x1;
              if first.index;
run;
data b;
  infile datalines truncover scanover;
  input index code year y1 y2 y3;
  cards;
  102003           10         2003       1       2       3
  102004           10         2004       2       3       4
  102005           10         2005       3       4       5
  102006           10         2006       4       5       6
  122003           12         2003       5       6       7
  122004           12         2004       6       7       8
  122005           12         2005       7       8       9
  122006           12         2006       8       9       10
  152004           15         2004       1       2       3
  162004           16         2004       2       3       4
  172005           17         2005       3       4       5
;
run;
proc sort data=a;
     by index code year;
run;
proc sort data=b;
    by index code year;
run;
data c;
    merge a b;
           by index code year;
run;
proc sql noprint;
    create table d as
           select  c.*,count(code) as count
               from c
                      group by code                             
                          ;
quit;
data d;
   set d;
     where count=4;
           keep index code year x1 x2 x3 y1 y2 y3;
run;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

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

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-20 10:19