BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shellp55
Quartz | Level 8

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

2 REPLIES 2
Reeza
Super User

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;
shellp55
Quartz | Level 8

Thanks Reeza!!   A perfect example of my trying to make it more difficult than it is!  

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 2 replies
  • 1894 views
  • 2 likes
  • 2 in conversation