How to rename a index key variable ?

Reply
New Contributor
Posts: 4

How to rename a index key variable ?


Hi all,

I have 5 dataset. Each dataset have the common column with different variable name.

I have a 6th dataset with the common colum alone. So i have indexed the 6th dataset.

Then myself matching 6th dataset with 1st to 5th dataset.

For matching dataset 6 with 1, it will be easy. but again matching 6th to 2nd, i have to rename the indexed variable.

So, please help me to rename indexed key variable.

Thanks

Jagathis P

Respected Advisor
Posts: 3,886

Re: How to rename a index key variable ?

Can you post some data steps creating sample data or at least post the data step / SQL used to join the 2 tables. That would help to clarify a few things.

New Contributor
Posts: 4

Re: How to rename a index key variable ?

Hi Patrick,

Please find the example code,

data inp_dataset_1;
    set inp_dataset;
    set dataset1 key=field1 / unique;    
   
  select(_iorc_);
when(%sysrc(_sok)) do;
  output;
        end;
     
      when(%sysrc(_dsenom)) do;
              put _N_=;
       put 'The SAS process has stopped' ;
       abort abend ;
      end;
      end;
run;


Data dataset1(Keep=field2);
set dataset1(rename=(field1=field2));

/*--- Checking if a field2 alerady exists in dataset1 ----*/

data inp_dataset_2;
    set inp_dataset_1;
    set dataset1 key=field2 / unique;    
   
  select(_iorc_);
when(%sysrc(_sok)) do;
                 output;
        end;
     
      when(%sysrc(_dsenom)) do;
             put _N_=;
       put 'The SAS process has stopped' ;
       abort abend ;
      end;
      end;
run;

Respected Advisor
Posts: 3,777

Re: How to rename a index key variable ?

data a(index=(a));
   do a = 1 to 5;
     
x = ranuni(1);
      output;
     
end;
  
run;
data test;
   do b = 5 to 1 by -1;
     
set a(rename=(a=b)) key=b/unique;
     
output;
     
end;
  
stop;
  
run;

data ac(index=(ac=(a c)));
   do a = 1 to 5;
     
do c = 1 to 2;
        
x = ranuni(1);
         output;
        
end;
     
end;
  
run;
data test2;
   do b = 5 to 1 by -1;
     
do c = 1 to 2;
        
set ac(rename=(a=b)) key=ac/unique;
        
output;
        
end;
     
end;
  
stop;
  
run;
Ask a Question
Discussion stats
  • 3 replies
  • 380 views
  • 0 likes
  • 3 in conversation