SAS中文论坛

标题: 再请教一个循环的问题 [打印本页]

作者: shiyiming    时间: 2009-12-18 11:45
标题: 再请教一个循环的问题
我现在的数据形式是date var1-var5
我想对一个date取前26天的数据做princomp;
princomp的程序如下(找了半天我想提取的数好像只能用ods提出来):
ods listing close;
ods output "Eigenvalues of the Correlation Matrix"=eigenv;
proc princomp data=temp noprint;
var var1-var5;
run;
ods output close;
ods listing;
data eigenv; set eigenv; keep number proportion; if number<=4;run;
proc transpose data=eigenv out=eigenf(drop=_name_) prefix=factor_;  
   id number;
   var proportion;
run;
这里的结果格式大概如下:
factor_1 factor_2 factor_3 factor_4
0.8           0.6            0.3      0.2
我想把这一组数写到原来相对应的那个date后面。

我对do循环比较晕,请问大虾们如何实现?谢谢!
作者: shiyiming    时间: 2009-12-18 12:59
标题: Re: 再请教一个循环的问题
还是没有学会怎么用简单的do循环,最后写了个macro,不过运行起来比较慢。大家给看看,如何能更有效率?
thanks a lot!


[code:1kt0zt21]
%macro movingpca;


%do i = 27 %to 373;

%put &i;
data tempi;
        set raw;
        if _N_=&i;
run;

data tempi2;
        set raw;
        if &i-26<=_N_<=&i-1;
run;

ods listing close;
ods output "Eigenvalues of the Correlation Matrix"=eigenv;
proc princomp data=tempi2;
var com_:;
run;
ods output close;
ods listing;
data eigenv; set eigenv; keep number proportion; if number<=4;run;
proc transpose data=eigenv out=eigenf(drop=_name_) prefix=factor_;
   id number;
   var proportion;
run;

data tempi4;
        merge tempi eigenf;
run;

data tempi5;
        set tempi5 tempi4;
run;

%end;
%mend;
%movingpca;

run;
[/code:1kt0zt21]
作者: shiyiming    时间: 2009-12-18 13:52
标题: Re: 再请教一个循环的问题
kaka,看来太麻烦。

问个小问题,在运行macro的时候如何不让他写log文件,要不总是过一会儿就说window is full什么的。
作者: shiyiming    时间: 2009-12-18 21:52
标题: Re: 再请教一个循环的问题
options nonotes; 总是有效--过后,最好再用option Notes 打开啊。
options nomprint nosymbolgen nomlogic; 关闭那些曾经开启的东西(?)
作者: shiyiming    时间: 2010-1-4 16:55
标题: Re: 再请教一个循环的问题
这个options nonotes只是不显示那些warning信息,在运行macro的时候还是会不停地在log显示运行到哪一步了,可不可以连这个都不显示呢?这是到结束的时候显示就好了?或者说直接把log写入硬盘某个文件,这样运行起来会比较快?

谢谢!
作者: shiyiming    时间: 2010-1-4 22:07
标题: Re: 再请教一个循环的问题
8489   data mus;
8490   input o3@@;
8491   call sound(o3, 300);
8492   cards;

[color=#0000BF:3gmqj3gw][i:3gmqj3gw]NOTE: SAS went to a new line when INPUT statement reached past the end of a
      line.
NOTE: The data set WORK.MUS has 7 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           4.21 seconds
      cpu time            0.09 seconds[/i:3gmqj3gw][/color:3gmqj3gw]

8494   ;
8495   run;

8496  [b:3gmqj3gw] options nonotes;[/b:3gmqj3gw]
8497   data mus;
8498   input o3@@;
8499   call sound(o3, 300);
8500   cards;
8502   ;
8503   run;

比较一下log里的信息,怎么会只是不显示warning呢?
作者: shiyiming    时间: 2010-1-4 22:34
标题: Re: 再请教一个循环的问题
我在运行macro,在这个option之前,是每运行一次都有notes,运行了nonotes现在是显示:
1
2
3
4



这样子的,但是因为我的数据太多,过一阵子(大约10万个数左右)还是会显示windows is full,要手动clean一次window才行,我想问有没有直接不显示log,或者在后台写入某文件的方式加快运行速度。
作者: shiyiming    时间: 2010-1-5 00:01
标题: Re: 再请教一个循环的问题
******************************
我没有很好的解决方法。只是想,可不可有条件地加入这样的SAS 命令:
[code:1ogogspc]dm 'log; clear;';[/code:1ogogspc]
比如说每100循环之后等等。
作者: shiyiming    时间: 2010-1-5 03:27
标题: Re: 再请教一个循环的问题
Please try the following to see if this meets your needs:

[i:1gzosrbn][color=#0000FF:1gzosrbn]proc printto log = '<path>\<filename1.ext>';
run;

proc printto print = '<path>\<filename2.ext>';
run;

<your code that may produce huge amount of information>

proc printto print = print;
run;

proc printto log = log;
run;[/color:1gzosrbn][/i:1gzosrbn]

The above approach should be able to direct all the information (e.g., source code, notes, warnings, errors, etc.) that would otherwise be output to the log window to the text file called &lt;path&gt;\&lt;filename1.ext&gt;. It would also write to the text file &lt;path&gt;\&lt;filename2.ext&gt; all the information that would otherwise be produced in the output window (such as output of proc sql/print/means/etc.). Once the program completes executing, you may review that two files as you need.  <!-- s:) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" /><!-- s:) -->




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