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

Hi,

I was wondering if it is possible to create a table based upon an other table and add an index immediatly?


basic Table_test

Naam

Key

Blabla

Boemboem

Jos

125634

Dq

Sddsf

Jos

125634

Cxc

Ffdfd

Maie

159631

Dsdjk

Jkhjk

Marius

178963

Sdsd

Ssds

Aline

345678

Dsdsdsdi

Ioyoyo

Aline

345678

Sdsds

Sdsdsd

Marc

456789

Szaéz

Azaz

Marc

456789

Sdsi

uuii

Result I would like to have.

Table_result

Id

Key

1

125634

2

159631

3

178963

4

345678

5

456789

PROC SQL;

   CREATE TABLE Table_result AS

   SELECT DISTINCT t1.Key

      FROM Table_test t1;

QUIT;

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

data want (keep=id key);

retain id;

set have;

by key;

if first.key then id+1;

if first.key;

run;

View solution in original post

4 REPLIES 4
Loko
Barite | Level 11

Hello,

Just add within the proc sql the create index line:

PROC SQL;

   CREATE TABLE Table_result AS

   SELECT DISTINCT t1.Key

      FROM Table_test t1;

     create index key on Table_result;

QUIT;

Liej
Calcite | Level 5

If I add the create index key I get this result

Table_result

Key

125634

159631

178963

345678

456789

stat_sas
Ammonite | Level 13

data want (keep=id key);

retain id;

set have;

by key;

if first.key then id+1;

if first.key;

run;

Liej
Calcite | Level 5

Thanks

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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