Hello
I have 10 occurrences of pxooh1-pxooh10 in wide format data. I want to rename occurrences from 2 to 10 as starting from 1 i.e. pxooh2 is renamed ooh_ind_px_1 and pxooh3 is renamed ooh_ind_px_2 and so on up to 10.
My current code is not working:
% macro N_renm_px2;
%do j = 2 %to 10;
pxooh&j=ooh_ind_px(&j-1)
%end;
%mend;
Any and all assistance greatly appreciated.
Have you tried a rename statement, I know it works if the index is the same and I think it should work here anyways:
rename pxooh2 - pxooh10 = ooh_ind_px_1 - ooh_ind_px_9;
EDIT: it works:
data have;
array indx(*) index02-index10;
do row=1 to 100;
do i=1 to 9;
indx(i)=i;
end;
output;
end;
run;
data want;
set have;
rename index02-index10=new_index1-new_index9;
run;
Have you tried a rename statement, I know it works if the index is the same and I think it should work here anyways:
rename pxooh2 - pxooh10 = ooh_ind_px_1 - ooh_ind_px_9;
EDIT: it works:
data have;
array indx(*) index02-index10;
do row=1 to 100;
do i=1 to 9;
indx(i)=i;
end;
output;
end;
run;
data want;
set have;
rename index02-index10=new_index1-new_index9;
run;
Thanks Reeza!! A perfect example of my trying to make it more difficult than it is!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.