> The reason is to rename the variables.i.e 12 months
> of sales we will have sls1 to sls12. after 12 months,
> the 13th month we will have new sales data and that
> will be called as sls1.
> and the previous months sales will be named from
> there on. i.e sls1 has to be renamed sls2, sls2 has
> to be renamed as sls3 so on.
are you seeking a renaming shortcut?
from a table holding columns sls1 - sls&n which are to be renamed as sls2 - sls%eval( &n +1 )
???
(if you have SAS9.2 rename in ranges works) try[pre]
libname your (work) ;[/pre]*first create data set with columns sls1-sls12;[pre]data your.original ;
retain sls1-sls12 123 ;
run;
proc contents data= your.original noprint out= _data_ ; run; [/pre]* getting column names;[pre]proc sql noprint ;
select max( input(substr( name, 4, 3), 3.)) into :N separated by ' '[/pre]without that input function, I got the maximum of the string which was 9, but we want 12[pre]from &syslast where lowcase(substr(name,1,3)) = "sls"
;
quit ;[/pre]* finally build new table renaming columns;[pre]data new_names ;
set your.original( rename= ( sls1-sls&N = _sls1-_sls&N ) );
rename _sls1-_sls&N = sls2-sls%eval( &N +1 ) ;
run;[/pre] needed the two stage rename at the end because it seems to validate each rename within the statement.