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!  

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 455 views
  • 2 likes
  • 2 in conversation