日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

sas table将缺失值计入百分比_SAS:通过数据块填充缺失值

發布時間:2025/3/15 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sas table将缺失值计入百分比_SAS:通过数据块填充缺失值 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

想象這樣做的代碼并不難,問題在于它很快就會顯得雜亂無章。

如果數據集不是太大,一個方法,你可以考慮以下方法:

/* We find all gaps. the output dataset is a mapping: the data of which minute (reference_minute) do we need to create each minute of data*/

data MINUTE_MAPPING (keep=current_minute reference_minute);

set YOUR_DATA;

by min;

retain last_minute 2; *set to the first minute you have;

if _N_ NE 1 and first.min then do;

/* Find gaps, map them to the last minute of data we have*/

if last_minute+1 < min then do;

do current_minute=last_minute+1 to min-1;

reference_minute=last_minute;

output;

end;

end;

/* For the available data, we map the minute to itself*/

reference_minute=min;

current_minute=min;

output;

*update;

last_minute=min;

end;

run;

/* Now we apply our mapping to the data */

*you must use proc sql because it is a many-to-many join, data step merge would give a different outcome;

proc sql;

create table RESULT as

select YD.current_minute as min, YD.rank, YD.qty

MINUTE_MAPPING as MM

join YOUR_DATA as YD

on (MM.reference_minute=YD.min)

;

quit;

更高性能的方法將涉及與陣列掛羊頭賣狗肉。 但我覺得這種方法更有吸引力(免責聲明:一開始就想到),之后其他人更快地掌握(免責聲明:imho)。

良好的措施,陣列方法:

data RESULT (keep=min rank qty);

set YOUR_DATA;

by min;

retain last_minute; *assume that first record really is first minute;

array last_data{5} _TEMPORARY_;

if _N_ NE 1 and first.min and last_minute+1 < min then do; *gap found;

do current_min=last_minute+1 to min-1;

*store data of current record;

curr_min=min;

curr_rank=rank;

curr_qty=qty;

*produce records from array with last available data;

do iter=1 to 5;

min = current_minute;

rank = iter;

qty = last_data{iter};

if qty NE . then output; *to prevent output of 5th element where there are only 4;

end;

*put back values of actual current record before proceeding;

min=curr_min;

rank=curr_rank;

qty=curr_qty;

end;

*update;

last_minute=min;

end;

*insert data for use on later missing minutes;

last_data{rank}=qty;

if last.min and rank<5 then last_data{5}=.;

output; *output actual current data point;

run;

希望它能幫助。 請注意,目前我無法訪問SAS客戶端。所以未經測試的代碼可能包含一些錯字。

總結

以上是生活随笔為你收集整理的sas table将缺失值计入百分比_SAS:通过数据块填充缺失值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。