BookmarkSubscribeRSS Feed
WorkingMan
Calcite | Level 5

I have tables that I want to set its own primary key and index.

Most of the tables will use ID/RK as Primary Key whereas index will be ID/RK + STARTDT

 

In SAS Data Integration Studio, setting ID/RK as primary key will also auto set ID/RK as index. If I want to set STARTDT as one of the indexes, it will prompt error saying primary key doesn't have STARTDT as key bla bla. I can provide the exact error message if you need. Only if i set STARTDT as primary key, index will auto include STARTDT.

 

This is not what I want. If i copy the auto generated code from SAS DI and paste it in EG, i can set as below by executing script in SAS EG with slight modification on my own:
Primary key: ID/RK

Index: ID/RK + STARTDT

 

In DI Studio, there is no way for me to have Primary key as ID/RK while having ID/RK + STARTDT as index.

 

Or is there anyway or workaround for me to do so in SAS DI Studio?

 

6 REPLIES 6
WorkingMan
Calcite | Level 5
Yes PK is unique. But we want to optimize the loading speed to ensure it runs at the most efficient way. PK+STARTDT for index is based on past experience and best practice in other non-SAS environment.

Is it a good practice/common way of having PK and index the same variable/column?
ChrisNZ
Tourmaline | Level 20

There is no point whatsoever in adding another variable to create a composite index that includes a unique variable.

The unique variable identifies the one record to retrieve. The other variable serves no purpose.

ChrisNZ
Tourmaline | Level 20
Now if you want to create another index that's a different matter.
WorkingMan
Calcite | Level 5
Can i achieve this without running into error in SAS EG?
ChrisNZ
Tourmaline | Level 20

I don't know what you are trying to achieve,

All this code is valid:

data CLASS; 
  set SASHELP.CLASS;
run;
proc sql;
  alter table CLASS add primary key(SEX,NAME);
quit;
proc contents ; run;

data CLASS; 
  set SASHELP.CLASS;
run;
proc sql;
 alter table CLASS(index=(A=(NAME SEX))) add primary key(NAME);
quit;
proc contents ; run;

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1254 views
  • 5 likes
  • 2 in conversation