BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
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
1 REPLY 1
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1 reply
  • 996 views
  • 0 likes
  • 2 in conversation