Help using Base SAS procedures

SAS dataset and view

Reply
Regular Contributor
Posts: 222

SAS dataset and view


Hello All.

Does anybody can briefly tell me  the difference between view and dataset? best with a small example.

Thanks!

Mike

Regular Contributor
Posts: 165

Re: SAS dataset and view

Lets asume you have a dataset A. We then create another dataset B and a view C that are exact copies of A.  If we then make a change to dataset A by adding or removing rows, etc. there will be no change to dataset B until we programatically update.  The view C, however, will be updated without submitting any statements.

data A;

val=1; output;

val=2;output;

val=3;output;

run;

data B;

set A;

run;

proc sql;

create view C as

select * from A;

quit;

data A;

set A;

where val ne 2;

run;

proc print data=B;

run;

proc print data=C;

run;

Super User
Posts: 10,538

Re: SAS dataset and view

Views may also be created to reference non-SAS data sources. Suppose you have a process that outputs a text file with the same name daily such as "d:\project\output.text". You could have a SAS view reference that data source. Each time the VIEW is used it re-reads that data so it always has the freshest version. If you place the VIEW in a permanent library such as below you only need to reference it like any other data set an it will re-read the data. Drawback: It re-reads the data every time it is referenced. If the external file is large the performance could be a significant problem.

data mylib.project / view=mylib.project;

     infile "d:\project\output.text" (various options as needed);

    input variables;

run;

I find views very useful when the component data sets are not terribly large but change frequently so the combined result doesn't require me to remember to rebuild everytime.

Super User
Posts: 5,093

Re: SAS dataset and view

Another feature:  views don't take up space.  They save the instructions for how to extract data, rather than the data itself.  This program needs to store a new data set:

data totals;

  set liquids;

   tot_liquid = 2* pints + 4*quarts;

run;

proc means data=totals;

   var tot_liquid;

run;

But by making a small change, and creating a view instead of a data set, the storage space requirements are virtually eliminated:

data totals / view=totals;

(The rest of the program remains the same.)

Super User
Posts: 9,687

Re: SAS dataset and view

View only contains the information using to search the real data (i.e. you can call it as SAS Code or SQL code), which doesn't contain any real data.

Table is actually dataset which contain the real data.

Ask a Question
Discussion stats
  • 4 replies
  • 236 views
  • 3 likes
  • 5 in conversation