BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yadaw
Fluorite | Level 6

Hi All,

 

I have a DATA SET called FR that has variables like: stu_id, name, age, gender. I want to create a simple index on stu_id using DATA step (Yes, we can do the same by PROC SQL or PROC DATASETS but here I want to create using DATA step).

I have written the below program but unable to create index:

DATA FR1 (INDEX=(stu_id=(stu_id)));

       SET FR;

RUN;

 

Can anybody help me on this?

And also, Is there any way to DELETE the created index by DATA step (I don't want to DELETE using PROC SQL or PROC DATASETS) ?

 

Thank You,

Yadaw

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

I could build an index, but don't know how to delete it yet.

 

data class(index=(name));
 set sashelp.class;
run;
proc contents data=class;
run;

Composite index.

data class(index=(comp=(name age)));
 set sashelp.class;
run;
proc contents data=class;
run;

View solution in original post

5 REPLIES 5
yadaw
Fluorite | Level 6

Hi All,

 

I have a DATA SET called FR that has variables like: stu_id, name, age, gender. I want to create a simple index on stu_id using DATA step (Yes, we can do the same by PROC SQL or PROC DATASETS but here I want to create using DATA step).

I have written the below program but unable to create index:

DATA FR1 (INDEX=(stu_id=(stu_id)));

       SET FR;

RUN;

 

Can anybody help me on this?

And also, Is there any way to DELETE the created index by DATA step (I don't want to DELETE using PROC SQL or PROC DATASETS) ?

 

Thank You,

Yadaw

Ksharp
Super User

I could build an index, but don't know how to delete it yet.

 

data class(index=(name));
 set sashelp.class;
run;
proc contents data=class;
run;

Composite index.

data class(index=(comp=(name age)));
 set sashelp.class;
run;
proc contents data=class;
run;
Ksharp
Super User
You could just simple copy the table to eliminate the index.

data x;
set class;
run;
proc contents data=x;
run;
RichardDeVen
Barite | Level 11

A data set index can be created in different ways

  • As specified by an output data set with option INDEX=
    • Simple indices (single columns) can not be named something else
    • Compound indices are specified <index-name>=(<column1> ... <column-n>)
  • PROC DATASETS; MODIFY
  • PROC SQL; CREATE INDEX

Index management is done with either DATASETS or SQL.  Read the documentation for more information about uniqueness and non-null indices and other data index topics such as integrity constraints and foreign keys.

 

Examples:

data cars(index=(Make Model type_drive=(Type DriveTrain)));
  set sashelp.cars;
run;

proc datasets nolist lib=work; 
  modify cars;
  index delete Make Model;
  index create Origin;
run;

proc sql;
  create index Make on work.cars;
  drop index type_drive from work.cars;
  create index type_cyl on work.cars(Type, Cylinders) ;

NOTE: SAS data sets do not have RDBMS features such as triggers or sequence numbers.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 5 replies
  • 450 views
  • 3 likes
  • 4 in conversation