全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2113 5
2014-03-20
具体问题如下。
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吗?

二维码

扫码加我 拉你入群

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

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

全部回复
2014-3-20 21:39:59
复制代码
二维码

扫码加我 拉你入群

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

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

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;
二维码

扫码加我 拉你入群

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

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

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;
二维码

扫码加我 拉你入群

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

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

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.
谢谢!!!!
二维码

扫码加我 拉你入群

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

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

2014-3-24 12:05:43
farmman60 发表于 2014-3-21 07:17
data have;
  input  ID   AGE;
  cards;
谢谢!!!!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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