SAS中文论坛

标题: 求助有关SAS提取数据进行运算的问题。 [打印本页]

作者: shiyiming    时间: 2009-8-4 11:32
标题: 求助有关SAS提取数据进行运算的问题。
数据是这样的:
date         time      a      b          c                d                 e                 f  
2007-9-20 15:50 43.26 31.4 906.1812 0.248863974 0.267639823 0.196451616
2007-9-20 16:00 45 31.25 803.6607 0.248863974 0.267369347 0.196401628
2007-9-20 16:10 44.54 31.15 732.6465 0.24857767 0.267369347 0.196265886
.......
.......
2007-9-24 23:20 88.17 25.77 17.5035 0.240853178 0.287935747 0.19089574
2007-9-24 23:30 88.37 25.77 17.5035 0.240853178 0.287935747 0.19089574
2007-9-24 23:40 88.68 25.77 17.0034 0.240853178 0.287935747 0.190939715
2007-9-24 23:50 90.37 25.67 17.0034 0.240853178 0.287935747 0.190939715
;
我需要将第五列c变量中time=23:50时刻的数据提取出来,另增加一列为g;然后以date为分组变量,将c变量值减去提取出来的值(23:50那刻的c值,即g值),生成变量h。为做毕业论文用,向各位高人求助!不胜感激!
作者: shiyiming    时间: 2009-8-4 12:02
标题: Re: 求助有关SAS提取数据进行运算的问题。
[color=#00FFFF:z0jd2hui][code:z0jd2hui]data aa;
input date:yymmdd10. time:time. a b c d e f ;
format date mmddyy10. time hhmm5.;
cards;
2007-9-20 23:20 43.26 31.4 906.1812 0.248863974 0.267639823 0.196451616
2007-9-20 23:30 45 31.25 803.6607 0.248863974 0.267369347 0.196401628
2007-9-20 23:50 44.54 31.15 732.6465 0.24857767 0.267369347 0.196265886
2007-9-24 23:20 88.17 25.77 17.5035 0.240853178 0.287935747 0.19089574
2007-9-24 23:30 88.37 25.77 17.5035 0.240853178 0.287935747 0.19089574
2007-9-24 23:40 88.68 25.77 17.0034 0.240853178 0.287935747 0.190939715
2007-9-24 23:50 90.37 25.67 17.0034 0.240853178 0.287935747 0.190939715
;
run;

data aa1;
set aa;
where time='23:50't;
run;


data bb;
if _n_ = 1 then do;
declare hash t(dataset:'aa1');
t.definekey('date');
t.definedata('c');
t.definedone();
end;
set aa(rename=(c=c1));
rc=t.find(key:date);
if rc=0 then do;
g=c;
h=c1-g;
output;
end;
run;[/code:z0jd2hui][/color:z0jd2hui]
作者: shiyiming    时间: 2009-8-4 15:22
标题: Re: 求助有关SAS提取数据进行运算的问题。
data bb;
if _n_ = 1 then do;
declare hash t(dataset:'aa1');
t.definekey('date');
t.definedata('c');
t.definedone();
end;
set aa(rename=(c=c1));
rc=t.find(key:date);
if rc=0 then do;
g=c;
h=c1-g;
output;
end;
run;
这段貌似有点问题declare语句出错。还请高人再指点一下! <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D -->
作者: shiyiming    时间: 2009-8-4 15:42
标题: Re: 求助有关SAS提取数据进行运算的问题。
declare没错呀,把LOG信息贴出来看看吧.
作者: shiyiming    时间: 2009-8-4 15:50
标题: Re: 求助有关SAS提取数据进行运算的问题。
15   data bb;
16   if _n_ = 1 then do;
NOTE: SCL source line.
17   declare hash t(dataset:'aa1');
     -------
     180
NOTE: SCL source line.
18   t.definekey('date');
                -
                22
ERROR: Invalid variable specification, t.definekey.
       Variable names of the form X.X must be either FIRST.X or LAST.X.
NOTE: SCL source line.
19   t.definedata('c');
                 -
                 22
ERROR: Invalid variable specification, t.definedata.
       Variable names of the form X.X must be either FIRST.X or LAST.X.
NOTE: SCL source line.
20   t.definedone();
                 -
                 22
                 76
ERROR: Invalid variable specification, t.definedone.
       Variable names of the form X.X must be either FIRST.X or LAST.X.
ERROR 180-322: Statement is not valid or it is used out of proper order.

ERROR 22-322: Syntax error, expecting one of the following: +, =.

ERROR 76-322: Syntax error, statement will be ignored.

21   end;
22   set aa(rename=(c=c1));
NOTE: SCL source line.
23   rc=t.find(key:date);
              -
              388
              76
ERROR: Invalid variable specification, t.find.
       Variable names of the form X.X must be either FIRST.X or LAST.X.
ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

24   if rc=0 then do;
25   g=c;
26   h=c1-g;
27   output;
28   end;
29   run;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      18:13   19:14
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.BB may be incomplete.  When this step was stopped there were 0
         observations and 12 variables.
NOTE: DATA statement used:
      real time           0.12 seconds
      cpu time            0.06 seconds
作者: shiyiming    时间: 2009-8-4 16:32
标题: Re: 求助有关SAS提取数据进行运算的问题。
看LOG信息SAS根本就没识别HASH对象,用的是V8吗?
作者: shiyiming    时间: 2009-8-4 16:35
标题: Re: 求助有关SAS提取数据进行运算的问题。
是哦,V8.0呢。还能有别的解决办法吗?
作者: shiyiming    时间: 2009-8-4 17:04
标题: Re: 求助有关SAS提取数据进行运算的问题。
[b:3f3gr4ax]这个可以么?[/b:3f3gr4ax][code:3f3gr4ax]data aa;
input date&#58;yymmdd10&#46; time&#58;time&#46; a b c d e f ;
format date mmddyy10&#46; time hhmm5&#46;;
cards;
2007-9-20 23&#58;20 43&#46;26 31&#46;4 906&#46;1812 0&#46;248863974 0&#46;267639823 0&#46;196451616
2007-9-20 23&#58;30 45 31&#46;25 803&#46;6607 0&#46;248863974 0&#46;267369347 0&#46;196401628
2007-9-20 23&#58;50 44&#46;54 31&#46;15 732&#46;6465 0&#46;24857767 0&#46;267369347 0&#46;196265886
2007-9-24 23&#58;20 88&#46;17 25&#46;77 17&#46;5035 0&#46;240853178 0&#46;287935747 0&#46;19089574
2007-9-24 23&#58;30 88&#46;37 25&#46;77 17&#46;5035 0&#46;240853178 0&#46;287935747 0&#46;19089574
2007-9-24 23&#58;40 88&#46;68 25&#46;77 17&#46;0034 0&#46;240853178 0&#46;287935747 0&#46;190939715
2007-9-24 23&#58;50 90&#46;37 25&#46;67 17&#46;0034 0&#46;240853178 0&#46;287935747 0&#46;190939715
;
run;

data aa1(index=(date/unique) keep=date c);
set aa;
where time='23&#58;50't;
run;

data want;
set aa(rename=(c=c1));
set aa1 key=date/unique;
if _iorc_ = 0 then do;
h=c1-c;
output;
end;
run;[/code:3f3gr4ax]
作者: shiyiming    时间: 2009-8-4 17:36
标题: Re: 求助有关SAS提取数据进行运算的问题。
可以,相当可以.
_IORC_ merge,又学一招.谢谢!!!
作者: shiyiming    时间: 2009-8-4 18:47
标题: Re: 求助有关SAS提取数据进行运算的问题。
太好了,运行下来了。非常感谢!这里真是藏龙卧虎啊,以后就上这个论坛了!




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2