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!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: