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