全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1205 5
2009-11-05
问题非本人原创,只是本人做不出来,发出来请教一下!!!


data A;
input acct sales;
cards;
1 23
1 33
1 54
2 32
2 34
;

数据是
1 23
1 33
1 54
2 32
2 34
需要
1 23 33
1 33 54
1 54 .
2 32 34
2 34 .
二维码

扫码加我 拉你入群

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

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

全部回复
2009-11-5 14:14:49
data A;
input acct sales;
cards;
1 23
1 33
1 54
2 32
2 34
;run;
data b;
  retain point 1;
  if _N_ < nobs then do;
    point = point + 1;
    set a point=point nobs=nobs;
    lead= sales;
  end;
  set a end=end;
run;
proc sort data=b;by acct;run;
data b;set b;by acct;
if last.acct then lead=.;run;
二维码

扫码加我 拉你入群

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

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

2009-11-5 16:26:19
PROC SORT DATA=A;
  BY acct DESCENDING sales;
RUN;

DATA B;
  SET A;
  BY acct DESCENDING sales;
  sales2=lag(sales);
  if first.acct then sales2=.;
RUN;

PROC SORT DATA=B;
  BY acct sales;
RUN;
二维码

扫码加我 拉你入群

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

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

2009-11-5 16:49:14
楼上可以测试下面的数据
1 23
1 33
1 54
2 32
2 34
2 32
二维码

扫码加我 拉你入群

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

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

2009-11-5 17:09:51
可以这样

data A;
input acct sales;
count+1;
cards;
1 23
1 33
1 54
2 32
2 34
2 32
;

PROC SORT DATA=A;
  BY acct DESCENDING count;
RUN;

DATA B;
  SET A;
  BY acct DESCENDING count;
  sales2=lag(sales);
  if first.acct then sales2=.;
RUN;

PROC SORT DATA=B;
  BY count;
RUN;

data b;
  set b;
  drop count;
run;
二维码

扫码加我 拉你入群

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

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

2009-11-8 02:42:44
Here is the one with simple logic.

1512  data need;
1513    set a end=end;
1514    by acct;
1515    n=_n_+1;
1516    if end=0 then set a (keep=sales rename=(sales=sales2)) point=n;
1517    if last.acct then sales2=.;
1518
1519
1520  run;

NOTE: There were 5 observations read from the data set WORK.A.
NOTE: The data set WORK.NEED has 5 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
1521
1522  proc print; run;

NOTE: There were 5 observations read from the data set WORK.NEED.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

  Obs    acct    sales    sales2

   1       1       23       33
   2       1       33       54
   3       1       54        .
   4       2       32       34
   5       2       34        .
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群