Steps to implementing a scan loop in SAS

Steps:

1. Store the number of observations in a data set to a macro variable (RECCOUNT)
2. Increment a variable (I) fromone to RECOUNT using a %DO loop

3. Use the FIRSTOBS option in a DATA step to advance to the record I
4. Store record values to macro variables using CALL SYMPUT
5. Perform any desired PROC and DATA steps

EXAMPLE:

In the following example, a log file (DATALOG) has been created of all the data sets in a library named TEST. Periodically, it is necessary to print the contents of these data sets into a series of quick reports. DATALOG consists of two columns, FILENM (the file name) and DESC (a short description). The reports should be formatted with a standard PROC PRINT and have a title consisting of the table description. The following piece of code accomplishes that task.

/* Macro to SCAN through DATALOG */
%macro scanloop(scanfile,field1,field2);
   /* First obtain the number of */
   /* records in DATALOG */
   data _null_;
      if 0 then set &scanfile nobs=x;
	  call symput("reccount",x);
	  stop;
   run;
   /* loop from one to number of records */
   %do i=1 %to &reccount;
   /* Advance to the Ith record */
   data _null_;
      set &scanfile(firstobs=&i);
      /* store the variables of interest in macro variables */
      call symput('var1',&field1);
	  call symput('var2',&field2);
	  stop;
   run;
   /* now perform the tasks that wish repeated for each observation */
   proc print data=&var1;
      title "&var2";
   %end;
%mend scanloop;
/* Call SCANLOOP */
%SCANLOOP(DATALOG,FILENM,DESC);
RUN;

摘自:http://www2.sas.com/proceedings/sugi26/p093-26.pdf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值