Creating a data step view

http://blog.renren.com/blog/220869953/732200049?from=fanyeOld 

THE details are from SAS Programming III :Advanced Techniques 

1 DATA Statement with VIEW= Option Syntax

data data-set-name / view=view-name;

        infile filref;

        input variables;

run;

data view = view-name;

        describe;

run;


 2 Example

data ia.movingq work.movingq / view = ia.movingq;
   drop MonNum MidMon LastMon I today;
   today = today();
   MonNum = month(today);
   MidMon = month(intnx('month',today,-1));
   LastMon = month(intnx('month',today,-2));
   do I = MonNum, MidMon, LastMon;
      NextFile = "month"||put(i,2.)||".dat"; * Windows/UNIX;
*Nextfile = ".prog3.rawdata(month"!!put(i,2.)!!")"; /* z/OS */
      NextFile = compress(NextFile,' ');
      do until (LastObs);
         infile in filevar = NextFile end = LastObs;
         input Flight $ Origin $ Dest $ Date : date9.
               RevCargo : comma15.2;
         output;
      end;
   end;
stop;
run;
proc print data = ia.movingq;
   title 'ia.movingq DATA Step View';
   title2 'triggers creation of work.movingq data set';
   var Flight Origin Date Dest RevCargo;
   format Date date9.;
run;


3 Advantages

You can use DATA step views to do the following:
 a. combine data from multiple sources
 b. hide complex code from users
 c. access the most current data in changing files
 d. avoid storing a SAS copy of a large data file
 e. avoid creating intermediate copies of data

4 Guidelines

 1)If data is used many times in one program, it is more efficient to create and reference a SAS data file than
    to create and reference a view.

data staff; 
   set ia.sview; 
run; 
proc print data = staff; 
proc freq data = staff; 
   tables JobCode; 
proc means data = staff; 
run;


2)Expect a degradation in performance when you use a SAS data view with a procedure that requires
multiple passes through the data.

proc print data = ia.sview uniform;
run;

proc means data=ia.sview ;

        class ...;run;

.........


3)Avoid creating views on files whose structures often change.

filename rawdata 'file1';
proc print data = ia.sview;
run;
filename rawdata 'file2'
proc freq data = ia.sview;
tables JobCode;
run;
filename rawdata 'file3'
proc means data = ia.sview;
run;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值