楼主: carol1222
2170 5

类似自动叠加赋值问题 [推广有奖]

  • 5关注
  • 0粉丝

硕士生

41%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1283 点
帖子
157
精华
0
在线时间
74 小时
注册时间
2010-5-6
最后登录
2014-11-13

楼主
carol1222 发表于 2014-3-20 16:11:26 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
具体问题如下。
ID     AGE
1      14
1      30
2      28
2      40

我有这么一个数据集,两个变量,一个ID一个年龄。
我知道ID=1的初始年龄从14-30,那么我希望数据集变成
ID     AGE
1        14
1        15
1        16
一直到。。。
1        30

这个要如何生成这样的数据库呢?

我的思路是做一个DO的循环,循环次数=30-14。然后每次+1;
是要做macro吗?

二维码

扫码加我 拉你入群

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

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

关键词:Macro 数据集 Age 数据库 CRO 数据库 如何

花有再开日 人无再少年

沙发
intheangel 学生认证  发表于 2014-3-20 21:39:59
  1. proc sort data=a;
  2. by id;

  3. data b;
  4. set a;
  5. delete;

  6. %macro a;
  7. %do i=1 %to 2;
  8. data c;
  9. set a;
  10. if id=&i;

  11. data c(keep=id sum);
  12. set c;
  13. by id;
  14. sum+age;
  15. if last.id;

  16. data b;
  17. set b c;
  18. run;
  19. %end;
  20. %mend a;
  21. %a;
复制代码
已有 1 人评分论坛币 收起 理由
admin_kefu + 50 热心帮助其他会员

总评分: 论坛币 + 50   查看全部评分

我是一只瘦瘦的小猪~~~
╭︿︿︿╮
{/-◎◎-/}
( (oo) )
  ︶︶︶

藤椅
farmman60 发表于 2014-3-21 07:17:21
data have;
  input  ID   AGE;
  cards;
1      14
1      30
2      28
2      40
  ;
  run;

  data want;  
    set have;
    by id;
         if first.id then do;
       _age=age;
       output;
           end;
          else do until (_age=age);
          _age+1;
          output;
          end;
          drop age;
          rename _age=age;
    run;

板凳
bobguy 发表于 2014-3-21 10:07:38
The macro is not the solution here.

Here is a simple data step with loops.
data have;
  input  ID   AGE;
  cards;
1      14
1      30
2      28
2      40
  ;
  run;

data want;  
    do _N_=1 by -1 until(last.id);
      set have;
          by id;
          if first.id then age_start=age;
          if last.id then do;
            age_stop=age;
        do age=age_start to age_stop by 1;
                  output;
            end;
          end;
        end;
        drop age_:;
run;

proc print;run;

报纸
carol1222 发表于 2014-3-24 12:05:12
bobguy 发表于 2014-3-21 10:07
The macro is not the solution here.

Here is a simple data step with loops.
谢谢!!!!
花有再开日 人无再少年

地板
carol1222 发表于 2014-3-24 12:05:43
farmman60 发表于 2014-3-21 07:17
data have;
  input  ID   AGE;
  cards;
谢谢!!!!
花有再开日 人无再少年

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

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