简体   繁体   English

sas宏拆分数据集应放在哪里

[英]sas macro split dataset where should it locate

I have a SAS macro part that will run the entire dataset and do some analysis, and during the analysis part, each instance is dealt with once a time.so that the entire dataset can be run and we could keep an eye on the 'log' file. 我有一个SAS宏部分,它将运行整个数据集并进行一些分析,在分析部分中,每个实例一次处理一次,以便可以运行整个数据集,我们可以密切注意'log文件。

However, I would like to split the entire dataset into several parts. 但是,我想将整个数据集分成几个部分。 (Ex, first 500 observations, 501~1000 observations, etc). (例如,前500个观测值,501〜1000个观测值等)。 Which means the engine will stop after running 500 instances, and then run again. 这意味着引擎将在运行500个实例后停止,然后再次运行。 And in the end they can be generated in one table as before. 最后,它们可以像以前一样在一个表中生成。 How can I add this 'split' part into my prior code? 如何将这个“拆分”部分添加到之前的代码中?

Initial Code: 初始代码:

 %macro mymac;
 OPTIONS NOTES SOURCE SOURCE2 MPRINT MLOGIC MERROR SYMBOLGEN;

 /* Part A starts*/

 data _null_;
 set WORK.LOCATION end=last;
    if last then call symput('nfiles',_n_);
 run;

 %do i=1 %to &nfiles;

 data _null_;
 set oriework.PO_LOC;
    if &i=_n_ then call symput('code',LOCATION_ID);
 run;

 /* Part A ends */

 %put &code;

 proc sql; 

 create table WORK.pt as select
 ......

 quit;

 %if %sysfunc(exist(WORK.result)) %then %do;
 data WORK.result;
 set WORK.result WORK.pt;
 run;
 %end;
 %else %do;
 data WORK.result;
 set WORK.pt;
 run;
 %end;


 %end;

 %mend;

 %mymac;

Where 'WORK.LOCATION' is the dataset that I call in 'proc sql' procedure that contains all the 'LOCATION_ID" information that I need. 其中“ WORK.LOCATION”是我在“ proc sql”过程中调用的数据集,其中包含我需要的所有“ LOCATION_ID”信息。

Part A is where Macro works that it runs from start to the end; A部分是Macro从头到尾运行的地方; can I replace it with a data splitting procedure so that every 500 observations are run altogether and finally combined to one table? 我可以用数据拆分程序代替它,以便每500个观测值一起运行,最后合并到一张表中吗?

Thank you! 谢谢!

Use a second macro do loop on dataset (around your proc sql statement), calling macro variables for a counter, the next start observation and the number of observations to process in the next batch. 在数据集上使用第二个宏do循环(在proc sql语句周围),调用宏变量作为计数器,下一个开始观察值以及下一批要处理的观察值数。 Then you can use these in dataset options using firstobs= and obs= eg (firstobs= &startobservation obs=&nobs) and the counter macrovar in the dataset name. 然后,您可以在数据集选项中使用firstobs=obs=来使用它们,例如(firstobs= &startobservation obs=&nobs)并在数据集名称中使用计数器macrovar。 This also works in proc sql . 这也适用于proc sql Just add the options to your from or join statement. 只需将选项添加到您的fromjoin语句即可。 Afterwards append the datasets using datastep , proc append or proc sql; insert into 然后使用datastepproc appendproc sql; insert into追加数据集proc sql; insert into proc sql; insert into

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM