简体   繁体   中英

How do I set Primary Key | SAS Studio

I'm trying to set Primary Key on SAS and I keep getting the error mentioned below. Any help would be great!

The first snippet is code and the next is the error.

/*Primary Key*/ /*Defines the unique key*/

Proc datasets lib=work;
modify WORK.FinAdvMaster;
ic create primary key(FinAdvID);
PROC PRINT DATA=WORK.FinAdvMaster; RUN;**strong text**

The error I get -

 96         /*Primary Key*/ /*Defines the unique key*/
 97         
 98         Proc datasets lib=work;
 99         modify WORK.FinAdvMaster;
                   _________________
                   22
                   201
 ERROR 22-322: Expecting a name.
 ERROR 201-322: The option is not recognized and will be ignored.
 100        ic create primary key(FinAdvID);
 NOTE: Enter RUN; to continue or QUIT; to end the procedure.

Remove work. from your modify statement. The lib= option specifies the library. It's a quirk of proc datasets .

proc datasets lib=work;
    modify FinAdvMaster;
        ic create primary key (FinAdvID);
quit;

Note that this key will be destroyed if you recreate the dataset.

You can use SQL to add a column constraint specifying PRIMARY KEY

Example:

proc sql; 

  create table work.class as select * from sashelp.class;

  alter table work.class add constraint pk_name primary key(name);

In your case

alter table FinAdvMaster
add constraint 
  pk_FinAdvID primary key(FinAdvID)
;

pk_ <column-name> is a common convention for naming primary keys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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