DATA Step, Macro, Functions and more

Appending data

Reply
Occasional Contributor
Posts: 10

Appending data

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;


 


 

Valued Guide
Posts: 537

Re: Appending data

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.

Ask a Question
Discussion stats
  • 1 reply
  • 101 views
  • 1 like
  • 2 in conversation