Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set Primary Key | SAS Studio

Tags:

sas

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.

like image 801
Amber Sethi Avatar asked Nov 25 '25 15:11

Amber Sethi


2 Answers

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.

like image 70
Stu Sztukowski Avatar answered Nov 28 '25 03:11

Stu Sztukowski


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.

like image 43
Richard Avatar answered Nov 28 '25 03:11

Richard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!