楼主: bridog
5697 15

数据处理proc transpose [推广有奖]

11
redbaby_jia 发表于 2012-11-14 23:28:05
data a;
input code   year   value;
cards;
1       2000    5
1       2000   6
1       2000  4.5
1      2000   5.3
1      2005   5.2
1      2005   6.4
1      2005   7
1      2005   7.8
2       2001    5
2       2001   6
2       2001  4.5
2      2001   5.3
2      2005   5.2
2      2005   6.6
2      2005   7.5
2      2005   8
;
run;
proc sql;
create table data1 as
select * from a
where year in (2000,2001);
run;
proc sql;
create table data2 as
select code,year as aaa,value as bbb from a
where year=2005;
run;
data final;
merge data1 data2;
by code;
run;
proc print data=final;
run;

12
bridog 发表于 2012-12-19 17:02:52
jingju11 发表于 2011-9-16 22:39
jingju
您好!根据您写的代码,却得到以下的数据结构:
area num year1 value1
1      1      2000  5
1      1      2005  5.2
1      2     2000   6
1      2     2005   6.4
。。。
几乎就没啥变化!这是为什么呢?谢谢了 !

13
jingju11 发表于 2012-12-19 22:34:57
when i run it, i got the results matched what you need.

jingju

14
bridog 发表于 2012-12-20 14:04:48
jingju11 发表于 2012-12-19 22:34
when i run it, i got the results matched what you need.

jingju
Jingju, thanks for your reply. But in the table have2 of my case, n always equals to 1.

bridog

15
jingju11 发表于 2012-12-20 22:24:51
bridog 发表于 2012-12-20 14:04
Jingju, thanks for your reply. But in the table have2 of my case, n always equals to 1.

bridog
I used the data you gave and the log and output as below. Not quite understand what happened to you. I think you have to have the data with the same formula as what you had given. Jingu
45   data have;
46   input area  num   year    value; datalines;

NOTE: The data set WORK.HAVE has 28 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


75   ;
76   data have2;
77           set have;
78           by area year notsorted;
79           if first.year then n ++1;
80           if first.area then n =1;
81   run;

NOTE: There were 28 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.HAVE2 has 28 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


82   data have3;
83           merge have2(where =(n =1) rename =(year =year1 value =value1))
84                 have2(where =(n =2) rename =(year =year2 value =value2))
85                 have2(where =(n =3) rename =(year =year3 value =value3))
86           ;
87           by area num;
88   run;

NOTE: There were 11 observations read from the data set WORK.HAVE2.
      WHERE n=1;
NOTE: There were 13 observations read from the data set WORK.HAVE2.
      WHERE n=2;
NOTE: There were 4 observations read from the data set WORK.HAVE2.
      WHERE n=3;
NOTE: The data set WORK.HAVE3 has 13 observations and 9 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


89   proc print; run;

NOTE: There were 13 observations read from the data set WORK.HAVE3.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.59 seconds
      cpu time            0.01 seconds


NOTE: This SAS session is using a registry in WORK.  All changes will be lost at the end of
      this session.
]

16
jingju11 发表于 2012-12-20 22:25:27
con't....
The SAS System    09:04 Thursday, December 20, 2012   1

     Obs    area    num  year1  value1  n    year2    value2    year3    value3

          1      1      1      2000      5.0     2     2005      5.2         .       .
          2      1      2      2000      6.0     2     2005      6.4         .       .
          3      1      3      2000      4.5     2     2005      7.0         .       .
          4      1      4      2000      5.3     2     2005      7.8         .       .
          5      2      1      2001      5.0     2     2005      5.2         .       .
          6      2      2      2001      6.0     2     2005      6.6         .       .
          7      2      3      2001      4.5     2     2005      7.5         .       .
          8      2      4      2001      5.3     2     2005      8.0         .       .
          9      2      5         .            .      2     2005      4.0         .       .
         10      3      1      1998      4.0     3     2002      5.0      2007      7.0
         11      3      2      1998      5.0     3     2002      6.0      2007      6.4
         12      3      3      1998      6.0     3     2002      4.5      2007       .
         13      3      4         .            .      3     2002      5.2      2007      6.8

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

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