DATA Step, Macro, Functions and more

rename

Reply
Super Contributor
Posts: 647

rename

How to rename?
I'm having difficulty to switch year i.e 2011 to 2010

Input date: 201104.

This date is used to rename everymonth vars sls1-sls24 as:
Sls1 to SLS201104
Sls2 to SLS201103
Sls3 to SLS201102
.
.
.SLS24

The nextmonth
Input date: 201105.

Sls1 to SLS201105 so on
Super Contributor
Super Contributor
Posts: 365

Re: rename

Hello SASPhile,

This is a solution for a next chapter of your renaming saga:
[pre]
%macro a(d0);
%global r;
%let r=rename;
%let m=%SYSFUNC(MOD(&d0,100));
%let y=%SYSFUNC(INT(&d0/100));
%put m=&m y=&y;
%let j=&d0;
%do i=1 %to 24;
%let r=&r SK&i=SLS&j;
%let m=%EVAL(&m-1);
%if &m = 0 %then %do; %let y=%EVAL(&y-1); %let m=12; %end;
%if &m LT 10 %then %let j=&y.0&m;
%else %let j=&y.&m;
%end;
%mend a;
%a(201104);
%put r=&r;
[/pre]
Sincerely,
SPR
Ask a Question
Discussion stats
  • 1 reply
  • 117 views
  • 0 likes
  • 2 in conversation