sas中的sql(7)创建视图,更新视图,删除视图

什么是视图?

视图是一系列的查询语句,在使用时被执行,用来从其他的数据集或视图中获取想要的子集(subset)或者超集(superset)。

The view contains only the logic for accessing the data, not the data itself

视图能用在哪些地方?

几乎在sas程序中任何真实表用的地方(不能用的地方暂未列出)。

使用视图的好处?

1:节约空间,视图往往比真实表要小很多。

2:防止用户经常进行表查询而忽略默写列,视图写好后每次调用就行,而inline-view需每次重写

3:保证数据集能进行实时更新。

4:掩盖其他表中的不想展现的列

5:对用户掩盖复杂的连接或查询

使用视图应该注意什么问题?

1:查询子句中尽量避免order by,使用view的用户的目的可能不同,是否使用order by应由不同的用户决定

2:避免创建基于容易变动的表的视图

3:如果同样的data要用很多次,那么最好不要创建视图而是直接创建静态表。

创建视图

创建视图时,系统并不会执行select的语句,只会编译并将其储存在视图类型的文件中。

 描述视图

如果建立的视图基于另一个视图上,那要用feedback选项才能描述出内容。

管理视图

如果view后面的视图指定了库名,那么from后的如果不指定库名则默认为在sasuser中。

proc sql;
    create view sasuser.payrollv as
        select *
            from payrollmaster;    
quit;

更灵活点的方式,using clause

libname airline 'SAS-library one';
proc sql;
create view sasuser.payrollv as
select*
    from airline.payrollmaster
    using libname airline 'SAS-library two';
quit;

sql中的libname语句不会影响外面的,可以看成局部语句

更新视图(语法和table一样)

1:You can only update a single table through a view. The table can not be joined or linked to another table, nor can it contain a subquery.

2:You can update a column using the column's alias, but you can not update a derived column

3:You can update a view that contains a WHERE clause. The WHERE clause can be,specified in the UPDATE clause or in the view. You cannot update a view that contains any other clause such as an ORDER BY or a HAVING clause.

4:You cannot update a summary view (a view that contains a GROUP BY clause). 

删除视图

 

原文地址:https://www.cnblogs.com/yican/p/4104715.html