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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 633 views
  • 0 likes
  • 2 in conversation