楼主: wellsuer
1339 6

[原创博文] 求教:如何在某些观测后面插入观测 [推广有奖]

  • 0关注
  • 1粉丝

已卖:1268份资源

硕士生

7%

还不是VIP/贵宾

-

威望
0
论坛币
5989 个
通用积分
88.4762
学术水平
1 点
热心指数
6 点
信用等级
1 点
经验
2997 点
帖子
82
精华
0
在线时间
151 小时
注册时间
2011-3-15
最后登录
2025-12-3

楼主
wellsuer 发表于 2012-6-19 10:06:48 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
数据集是这样的
X
a
b
c
a
b
a
b
c
a
b
如果b后面没有c,则在b后面插入c;
最终希望的结果是这样的:
a
b
c
a
b
c
a
b
c
a
b
c
二维码

扫码加我 拉你入群

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

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

关键词:数据集 如何

回帖推荐

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

Take a look of a point access option of data set. Here is an example. data x; input X $1.; cards; a b c a b a b c a b ; data y; set x nobs=nobs end=end; cnt=_n_+1; if cnt

沙发
wellsuer 发表于 2012-6-19 10:07:30

藤椅
cswcbqkl 在职认证  发表于 2012-6-19 10:19:17
有点奇怪

板凳
tj0412ymy 发表于 2012-6-19 11:07:48
  1. data test;
  2. input x $;
  3. cards;
  4. a
  5. b
  6. c
  7. a
  8. b
  9. a
  10. b
  11. c
  12. a
  13. b
  14. ;
  15. run;
  16. %macro final;
  17. proc sql;
  18. create table test1 as
  19. select distinct * from test;
  20. select count(distinct x) into : obs from test1;
  21. %let obs=%cmpres(&obs.);
  22. select distinct x into: m1 - :m&obs. from test1;
  23. select max(%do j=1 %to &obs.-1; sum(x="&&m&j."),%end;sum(x="&&m&obs.")) into: m
  24. from test;
  25. quit;
  26. data final;
  27. set %do i=1 %to &m.; test1 %end;;
  28. run;
  29. proc print noobs;run;
  30. %mend;
  31. %final;
复制代码
对SAS和统计方面感兴趣的朋友,请加SAS学习和认证讨论群:169157207。欢迎在群上讨论!

报纸
bobguy 发表于 2012-6-20 09:44:16
Take a look of a point access option of data set. Here is an example.

data x;
input X $1.;
cards;
a
b
c
a
b
a
b
c
a
b
;

data y;
  set x nobs=nobs end=end;
  cnt=_n_+1;
  if cnt<nobs then set x(rename=(x=x2)) point=cnt;
  output;
  if x='b' and x2 ne 'c'  then do;
     x='c';
         output;
  end;
  keep x;
run;
proc print;run;

地板
wellsuer 发表于 2012-7-2 16:13:37
bobguy 发表于 2012-6-20 09:44
Take a look of a point access option of data set. Here is an example.

data x;
thanks very much

7
wellsuer 发表于 2012-7-2 16:14:22
tj0412ymy 发表于 2012-6-19 11:07
thanks very much.

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

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