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

can any 1 please tell me is this a correct way to create a unique id using 2 variables??????

 

data car_sales_new;
set _class_s.car_sales;
length uniqueID $30;
uniqueID = catx("111", Model,Manufacturer);
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Have you run the sort ? Did you get 0 deleted observations ? - Probably NOT

because you sort by manufacturer only, and most of them have more than one model !

 

You should sort by manufactrer model; and if you get 0 deleted obs then those two variables 

combine a unique key.

 

Regarding your 2nd step, the statement: uniqueID = catx("Manfmod", Model,Manufacturer);

will result in your 1st row into:  "IntegraManfmodAcura" - is that what you want ?

If you cahnge it to: uniqueID = catx("-", Model,Manufacturer); you will get  "Integra-Acura";

Or maybe you intended to write:  Manfmod = catx('-',Manufacturer,Model); to get Manfmod = "Acura-Integra" ???

 

If you want the output to be sorted by the created unique key then 

sort by same order of variables as in concatenation (left to right).

 

 

 

 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

You'll have to explain the problem in more detail.

 

We don't know what you mean by "unique".

 

We don't know what result you want to get.

 

And what happens when you run this code, why are you dissatisfied with it?

--
Paige Miller
Shmuel
Garnet | Level 18

A unique ID depends on the data.

 

Concatenation "111" to all observations does not contribute to uniqueness.

 

If a model has submodels then concatenating model with manufacturer will not give a unique ID.

 

you can check uniqueness by:

proc sort data=have out=test NODUPKEY;
    by <key variables>;
run;

If there are 0 deleted observations then the combination given by <key variables> is unique.

mehak
Calcite | Level 5

this way u are saying sir ;

 

proc sort data =car_sales_new out=car_sales_new NODUPKEY ;

by Manufacturer;

run;

data car_sales_new;

set _class_s.car_sales;

length uniqueID $50;

uniqueID = catx("Manfmod", Model,Manufacturer);

run;

 

 
Shmuel
Garnet | Level 18

Have you run the sort ? Did you get 0 deleted observations ? - Probably NOT

because you sort by manufacturer only, and most of them have more than one model !

 

You should sort by manufactrer model; and if you get 0 deleted obs then those two variables 

combine a unique key.

 

Regarding your 2nd step, the statement: uniqueID = catx("Manfmod", Model,Manufacturer);

will result in your 1st row into:  "IntegraManfmodAcura" - is that what you want ?

If you cahnge it to: uniqueID = catx("-", Model,Manufacturer); you will get  "Integra-Acura";

Or maybe you intended to write:  Manfmod = catx('-',Manufacturer,Model); to get Manfmod = "Acura-Integra" ???

 

If you want the output to be sorted by the created unique key then 

sort by same order of variables as in concatenation (left to right).

 

 

 

 

mehak
Calcite | Level 5

 

After  sorting  by manufactrer model;  getting 0 deleted obs then i have  two variables 

combine a unique key.

 uniqueID = catx("-", Model,Manufacturer);

 

Solved the answer thankyou so much 

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