首页 > 解决方案 > 无法使用不同于创建视图的库名读取 SAS 视图

问题描述

我在 SAS 中创建了一个视图来读取多个数据集。仅当我提供用于创建视图的相同 libname 时,我才能从该视图中读取数据。

libname test "c:\temp";
data test.one; x=1; run; 
data test.two; x=2; run;
data test.three; x=3; 
run;proc sql ; 
create view test.master as     
   select * from test.one     union   
   select * from test.two     union
   select * from test.three; 
quit;  
data test;
    set test.master; 
run;

上面的代码运行良好,但是当我打开一个新的 sas 会话并使用不同的 libname 时,如下所示,我收到错误:

libname new "c:\temp";
data test; 
    set new.master;
run; 
ERROR: Libref TEST is not assigned.
ERROR: Libref TEST is not assigned.
ERROR: Libref TEST is not assigned. 
ERROR: SQL View TEST.PANEL2 could not be processed because at least one of the data sets, or views, referenced directly (or 
   indirectly) by it could not be located, or opened successfully.

请指教

标签: viewsas

解决方案


我不确定我是否认为这是个好主意,但如果您确实想这样做,那么您可以将 libname 定义嵌入到带有using子句的视图中。将路径也放入视图名称中,您甚至根本不必创建 libref test

proc sql ; 
create view 'C:\temp\master' as     
   select * from test.one     union   
   select * from test.two     union
   select * from test.three
   using libname test 'C:\temp' 
; 
quit;  

现在您不需要使用相同的 libref,但请注意您需要使用相同的物理位置。


推荐阅读