BookmarkSubscribeRSS Feed
rajat1
Fluorite | Level 6

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 :-

ManufacturerModelSales in thousands4-year resale valueVehicle type       
excsds111.31311.26Car       
abcfgfvg101.323.Car       
xxxdfrg181.74912.025Car       
aaaEscort           70.2277.425Passenger       

 

 

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;


 


 

1 REPLY 1
jklaverstijn
Rhodochrosite | Level 12

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 785 views
  • 1 like
  • 2 in conversation