繁体   English   中英

SAS获取表主键

[英]SAS getting table primary key

我对SAS 4GL完全陌生...

是否可以从表中提取哪些列是主键或复合主键的一部分? 我需要将它们的值合并到输出数据集的一列中。

问题是,作为输入,我可以获得不同的表,而我不知道它们的定义。

如果定义了索引,则可以找出该索引中使用了哪些变量。 参见例如:

data blah(index=(name));
set sashelp.class;
run;

proc contents data=blah out=blahconts;
run;

blahconts列指示该name位于简单索引中,并且总共具有1个索引。

另外,您可以具有外键约束,例如此SAS文档示例中的以下内容:

proc sql;
   create table work.mystates
      (state      char(15), 
       population num,
       continent  char(15),

          /* contraint specifications */
       constraint prim_key    primary key(state),
       constraint population  check(population gt 0),
       constraint continent   check(continent in ('North America', 'Oceania')));      

   create table work.uspostal
      (name      char(15),
       code      char(2) not null,          /* constraint specified as    */
                                            /* a column attribute         */

       constraint for_key foreign key(name) /* links NAME to the          */
                  references work.mystates   /* primary key in MYSTATES    */

                     on delete restrict     /* forbids deletions to STATE */
                                            /* unless there is no         */
                                            /* matching NAME value        */

                     on update set null);   /* allows updates to STATE,   */
                                            /* changes matching NAME      */
                                            /* values to missing          */ 
quit;

proc contents data=uspostal out=postalconts;
run;
proc sql;
describe table constraints uspostal;
quit;

这会将约束信息写入输出窗口。 从输出数据集中,您可以看到变量位于简单索引中。 您可以将这些( PROC CONTENTSDESCRIBE TABLE CONSTRAINTS )包装在ODS OUTPUT中,以将信息获取到数据集:

ods output  IntegrityConstraints=postalICs;
proc contents data=uspostal out=postalconts;
run;
ods output close;

要么

ods output  IntegrityConstraints=postalICs;
proc sql;
describe table constraints uspostal;
quit;
ods output close;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM