问题描述
我在谷歌上找不到任何东西.
I couldn't find anything on google.
我有一个数据集,需要分块迭代它,第一个块是:firstobs = 1 obs = 30000第二块是:firstobs = 30001 obs = 60000第三:firstobs = 60001 obs = 90000
I have a data set and need to iterate it in chunks,first chunk would be:firstobs = 1 obs = 30000second chunk would be:firstobs = 30001 obs = 60000third:firstobs = 60001 obs = 90000
等等……
有可能吗?这种东西怎么写?
Is it possible?How do I write such thing?
已编辑
我有这些数据,正在处理几百万条记录:
I have this data, working on several million records:
data _null_;
set all_include_Stornos ;
IF TREATMENT_IND = 1 AND DDS_ROW_IND NE 1 THEN DO;
CALL EXECUTE ('%STORNO_TKUFA ('||POLICY_RK||');');
CALL EXECUTE ('%UPDATE (STORNO_TKUFA_CUMULATE);');
END;
IF TREATMENT_IND in (4) AND DDS_ROW_IND NE 1 THEN DO;
CALL EXECUTE ('%HAKPAA ('||POLICY_RK||','||POLICY_VERSION||');');
call execute ('%UPDATE(HAKPAA_CUMULATE);');
END;
IF TREATMENT_IND = 5 AND DDS_ROW_IND NE 1 and count_bitul_no <2 or (count_bitul_no >1 and max_bitul_ver = policy_verSion ) THEN DO;
CALL EXECUTE ('%BITUL ('||POLICY_RK||','||POLICY_VERSION||');');
CALL EXECUTE ('%UPDATE(BITUL_CUMULATE);');
END;
IF TREATMENT_IND = 6 AND DDS_ROW_IND NE 1 THEN DO;
CALL EXECUTE ('%LAST_STATE ('||POLICY_RK||','||POLICY_VERSION||');');
CALL EXECUTE ('%UPDATE (LAST_STATE_calc);');
END;
IF DDS_ROW_IND NE 1 and ((PREV_TREATMENT_IND = 4 AND TREATMENT_IND NOT IN (1,2,5)) or treatment_ind = 3) THEN DO;
CALL EXECUTE ('%HAFSHARA ('||POLICY_RK||','||POLICY_VERSION||');');
CALL EXECUTE ('%UPDATE (HAFSHARA_CUMULATE);');
END;
IF TREATMENT_IND = 2 AND POLICY_VERSION - 1 = max_bitul_ver AND DDS_ROW_IND NE 1 THEN DO;
CALL EXECUTE ('%STORNO_BITUL ('||POLICY_RK||','||POLICY_VERSION||');');
CALL EXECUTE ('%UPDATE (STORNO_BITUL_CUMULATE);');
END;
RUN;
根据论坛成员的建议,由于调用执行工作的方式,我需要将数据分成块,这样程序就不会像现在一样崩溃,
As recommended by forum's members,because of the way Call Executed work,I need to split the data into chunks, so the program won't collapsed , as it did till now,
所以我想到了一个循环,每次迭代都将 firstobs 增加 30K.
so I thought of a loop taking firstobs and increment it by 30K on each and every iteration.
问题是,到目前为止,我无法让 firstobs 使用变量
Problem is, I couldn't get firstobs to work with a variable so far
推荐答案
写一个宏来做你想做的事.
Write a macro to do what you want.
%macro loop(max,by);
%do i=%eval(1+&by) %to &max %by &by;
data _null_;
set all_include_Stornos(firstobs=%eval(&i-&by) obs=&i);
...
run;
%end;
%mend;
%loop(90001,30000)
意识到我应该解释 fisrtobs= 和 obs= 的工作原理.基本上,它从记录firstobs"开始,到obs"结束.因此,您使用宏循环从 1 到 90001 乘以 30000.这样您一次只能处理 30k 条记录.如果您需要减小块大小,您可以随时更改宏中的by"值.
Realized I should explain how fisrtobs= and obs= work. Basically, it starts at record "firstobs" and ends at "obs". So you use a macro loop to go from 1 to 90001 by 30000. This way you only process 30k records at a time. You can always change the "by" value in the macro if you need to reduce the chunk size.
这篇关于动态第一观察:需要在firstobs=中放一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!