簡體   English   中英

SAS 宏:如何在一個數據集中記錄 proc 表示 output?

[英]SAS Macro: How can I record proc means output in one dataset?

[我有這段代碼。 但是,由於循環 t 從 1 到 310,proc 單變量中的宏生成了太多單獨的數據集。如何修改此代碼以將所有 proc 單變量 output 包含到一個數據集中,然后修改代碼的 rest 以更有效地運行? ]


%let L=10; %* 10th percentile *;
%let H=%eval(100 - &L); %* 90th percentile*;
%let wlo=V1&L V2&L V3&L ;
%let whi=V1&H V2&H V3&H ;
%let wval=wV1 wV2 wV3 ;
%let val=V1 V2 V3;

%macro winsorise();

%do v=1 %to %sysfunc(countw(&val));
%do t=1 %to 310;
proc univariate data=regressors noprint;
var &val;
output out=_winsor&t._V&v pctlpts=&H &L
prtlpre=&val&t._V&v;
where time_count<=&t;run;
%end;
data regressors (drop=__:);
set regressors;
if _n_=1 then set _winsor&t._V&v;
&wval&t._V&v=min(max(&val&t._V&v,&wlo&t._V&v),&whi&t._V&v);
run;
%end;
%mend;

謝謝你。

假設您有數據time_countx1x2x3 ,每 0.5 個時間單位有樣本。

data regressors;
  call streaminit(123);
  do time_count = 0 to 310 by .5;
    x1 = 2 ** (sin(time_count/6) * log(time_count+1));
    x2 = log2 (time_count+1) + log(time_count/10+.1);
    x3 = rand('normal', 
    output;
  end;
  format x: 7.3;
run;

根據 integer time_count 級別將數據堆疊成組。 堆棧由具有小於 ( <= ) 標准的完全外連接構成。 每個組由組中的頂部time_count 標識。

proc sql;
  create table stack as
  select 
    a.time_count
  , a.x1
  , a.x2
  , a.x3
  , b.time_count as time_count_group            /* save top value in group variable */
  from      regressors as a
  full join regressors as b                     /* self full join */
  on a.time_count <= b.time_count               /* triangular criteria */
  where
  int(b.time_count)=b.time_count                /* select integer top values */
  order by
  b.time_count,  a.time_count
  ;
quit;

現在計算一個 go 中所有組的所有變量的所有統計數據。 沒有宏觀,沒有混亂,沒有大驚小怪。

proc univariate data=stack noprint;
 by time_count_group;
 var x1 x2 x3;
 output out=_winsor n=group_size pctlpts=90 10 pctlpre=x1_ x2_ x3_; 
run;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM