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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1035 views
  • 0 likes
  • 2 in conversation