Creating a data step view

来源:互联网 发布:英语句子成分分析软件 编辑:程序博客网 时间:2024/05/04 00:27
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;

原创粉丝点击