Make 2 separate data sets containing the variable
1. unique id ,Manufacturer,model
2. unique id and remaining variable
I AM NOT HAVING A UNIQUE ID IN MY DATA SET IN THIS CASE . WHAT SHOULD I DO ?
Data set is :-
Manufacturer | Model | Sales in thousands | 4-year resale value | Vehicle type | |||||||
exc | sds | 111.313 | 11.26 | Car | |||||||
abc | fgfvg | 101.323 | . | Car | |||||||
xxx | dfrg | 181.749 | 12.025 | Car | |||||||
aaa | Escort | 70.227 | 7.425 | Passenger |
code:
Data a_sales ;
set _class_s.a_sales;
keep Manufacturer Model ;
run;
proc print data=a_sales;
run;
Data a_sales ;
set _class_1.a_sales;
drop Manufacturer Model ;
run;
proc print data=a_sales;
run;
It would help if you more clearly explained your problem. I go by the assumption that you do not have a unique id and want a way to make one.
"If" manufacturer and model together are unqiue, this would be one way:
Data a_sales ;
set _class_s.a_sales;
keep Unique_id Manufacturer Model ;
Unique_id = md5(cats(Manufacturer, Model));
run;
proc print data=a_sales;
run;
Data a_sales ;
set _class_1.a_sales;
drop Manufacturer Model ;
Data a_sales ;
set _class_s.a_sales;
keep Manufacturer Model ;
run;
proc print data=a_sales;
run;
Data a_sales ;
set _class_1.a_sales;
drop Manufacturer Model ;
Unique_id = md5(cats(Manufacturer, Model));
run;
proc print data=a_sales;
run;
run;
proc print data=a_sales;
run;
MD5() or it's more modern sibling SHA256() make a hash of it's character argument in a reproducable way. Another approach would take the row number but that can change and is not my preference. But it's up to you.
Hope this helps,
- Jan.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.