Help using Base SAS procedures

PROC DATASETS - CHANGE Statement

Reply
Occasional Contributor
Posts: 7

PROC DATASETS - CHANGE Statement

Hi. I have a very easy problem that i can't seem to google myself out of. I've searched the forums, but without luck.

I want renames more sas dataset
ex: current dataset names : x_2011, x_2010, x_2009, x_2008 ...
new_manes: p_2011, p_2010, p_2009, p_2008 ...

I can use
PROC DATASETS LIBRARY=xxx;
CHANGE db_old=db_new;

QUIT;RUN;

but I won't repeat db's name.

How can I do?

Thanks in advance ...
Respected Advisor
Posts: 3,777

Re: PROC DATASETS - CHANGE Statement

I believe the only way is to "gen the code".

[pre]
188 data x_2011 x_2010 x_2009 x_2008;
189 stop;
190 run;

NOTE: The data set WORK.X_2011 has 0 observations and 0 variables.
NOTE: The data set WORK.X_2010 has 0 observations and 0 variables.
NOTE: The data set WORK.X_2009 has 0 observations and 0 variables.
NOTE: The data set WORK.X_2008 has 0 observations and 0 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


191 proc sql noprint;
192 select catx('=',memname,cats('s',substr(memname,2))) into :change separated by ' '
193 from dictionary.members
194 where libname eq 'WORK' and memname eqT 'X_';
195 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


196 run;
197 %put NOTE: CHANGE=&change;
NOTE: CHANGE=X_2008=s_2008 X_2009=s_2009 X_2010=s_2010 X_2011=s_2011
198 proc datasets;
Directory

Libref WORK
Engine V9
Physical Name (system-specific file/path name)


Member
# Name Type

1 X_2008 DATA
2 X_2009 DATA
3 X_2010 DATA
4 X_2011 DATA
199 change &change;
200 run;

NOTE: Changing the name WORK.X_2008 to WORK.S_2008 (memtype=DATA).
NOTE: Changing the name WORK.X_2009 to WORK.S_2009 (memtype=DATA).
NOTE: Changing the name WORK.X_2010 to WORK.S_2010 (memtype=DATA).
NOTE: Changing the name WORK.X_2011 to WORK.S_2011 (memtype=DATA).
201 quit;

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
[/pre]
Occasional Contributor
Posts: 7

Re: PROC DATASETS - CHANGE Statement

I never can find this solution
Thank you very much!
Ask a Question
Discussion stats
  • 2 replies
  • 134 views
  • 0 likes
  • 2 in conversation