标题: Macro求救 [打印本页] 作者: shiyiming 时间: 2009-8-10 13:41 标题: Macro求救 我有个dataset,大致如下:
name time trade
AAA 9:00:00 xx
AAA 13:00:00 xx
AAA 15:20:30 xx
BBB 8:20:30 xx
BBB 12:30:00 xx
... ... ...
要求用macro计算各个公司上下午的trade frequency,以及上下午的trade frequency
different。
我把公司的名字已经从上面提取出来放在firms这个file里面了,上面的dataset我也标
记了timeflag,上午0,下午1;
下面是我的程序:
data allfirm;
set test3;
if time<"12:00:00" then timeflag=0;
if time>="12:00:00" then timeflag=1;
run;
%let firms=&firms; (这里显示:WARNING: Apparent symbolic reference FIRMS
not resolved.
ERROR: The text expression &FIRMS contains a recursive reference to the
macro variable FIRMS. The macro variable will be assigned the null value.)
%global dsnames;
%macro dowork (whichfirm);
proc means whatever data=allfirm(where=(firm="&whichfirm"));
by timeflag;
var trade;
output out=tradefreq_&whichfirm(drop=_type_ _freq_) N=/trade_N;
end;
%mend dowork;
%repeatwork;
这里显示:WARNING: Apparent invocation of macro REPEATWORK not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.
ERROR: Invalid macro name ;. It should be a valid SAS identifier no longer
than 32 characters.
ERROR: A dummy macro will be compiled.
另外,怎么求different of trade frequency between morning and afternoon?
不知道我说清楚了么?作者: shiyiming 时间: 2009-8-10 17:51 标题: Re: Macro求救 另外还有个问题,这里我想把上下午标识出来,原来test1里面 time format为time8.
这一句:
163 data allfirm;
164 set test1;
165 if time<"12:00:00" then timeflag=0;
166 if time>="12:00:00" then timeflag=1;
167 run;
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
165:16 166:17
NOTE: Invalid numeric data, '12:00:00' , at line 165 column 16.
NOTE: Invalid numeric data, '12:00:00' , at line 166 column 17.
这该怎么办?作者: shiyiming 时间: 2009-8-10 19:12 标题: Re: Macro求救 [code:jyjw08pi]data original;
input name $ time time8. trade;
if time<'12:00:00't then timeflag=0;
else timeflag=1;
format time time8.;
datalines;
AAA 9:00:00 10
AAA 13:00:00 20
AAA 15:20:30 30
BBB 8:20:30 40
BBB 9:30:00 50
BBB 12:30:00 60
;
%macro convert(in_ds,out_ds);
options nosymbolgen nomprint;
proc sort data=&in_ds out=&out_ds;
by name timeflag;
run;
data &out_ds;
do trade_freq=1 by 1 until(last.timeflag);
set &out_ds;
by name timeflag;
end;
run;
data &out_ds(drop=temp);
set &out_ds;
by name;
temp=lag(trade_freq);
if last.name=1 then trade_dif=temp-trade_freq;
run;
%mend;
Thank you very much!!!作者: shiyiming 时间: 2009-8-10 22:06 标题: Re: Macro求救 原数据库里有的trade data missing,如果用trade_freq=1 by 1,这个语句是不是不管有没有数都会count?
不过我对那个dataset处理了一下,去掉了missing data。
不知道有没有别的方法处理?作者: shiyiming 时间: 2009-8-10 22:46 标题: Re: Macro求救 trade eq . 时不参加计算是吗? 改过了。
[code:3h0bjcog]data original;
input name $ time time8. trade;
if time<'12:00:00't then timeflag=0;
else timeflag=1;
format time time8.;
datalines;
AAA 9:00:00 10
AAA 13:00:00 .
AAA 15:20:30 30
BBB 8:20:30 .
BBB 9:30:00 50
BBB 12:30:00 60
;
%macro convert(in_ds,out_ds);
options nosymbolgen nomprint;
proc sort data=&in_ds out=&out_ds;
by name timeflag;
run;
data &out_ds(drop=_i trade time);
trade_freq=0;
do _i=1 by 1 until(last.timeflag);
set &out_ds;
by name timeflag;
if trade ne . then trade_freq+1;
end;
run;
data &out_ds(drop=temp);
set &out_ds;
by name;
temp=lag(trade_freq);
if last.name=1 then trade_dif=temp-trade_freq;
run;
%mend;