簡體   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