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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With