DATA Step, Macro, Functions and more

concatenation variables

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

concatenation variables

[ Edited ]

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;


Accepted Solutions
Solution
‎10-21-2017 12:18 PM
Trusted Advisor
Posts: 1,831

Re: concatenation variables

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


All Replies
Respected Advisor
Posts: 2,802

Re: concatenation variables

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
Trusted Advisor
Posts: 1,831

Re: concatenation variables

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.

Contributor
Posts: 30

Re: concatenation variables

[ Edited ]

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;

 

 
Solution
‎10-21-2017 12:18 PM
Trusted Advisor
Posts: 1,831

Re: concatenation variables

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).

 

 

 

 

Contributor
Posts: 30

Re: concatenation variables

 

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 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 178 views
  • 0 likes
  • 3 in conversation