BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
CSB35
Obsidian | Level 7

Hi, I am trying to create a header for my table that reads "2023 Actual."  

 

The purpose of this is to compare what we spent in the prior year compared to the current year. 

My program prompts the user for the current year as a 4 digit numeric variable called "Vyear" which is the current year, or 2024 in this example.

 

As of now, when I run the attached code the header reads as "2024-1 Actual" as text. (see attached image). My goal is to have the header "2023 Actual" 

 

I made the current year as numeric to avoid having to create an additional prompt that asks for what year it was last year in hopes that I could do Vyear(current year) -1 to return the prior year. Ex: 2024 would become 2023.

Supp.JPG%put &VYear;
%let VP = &Vyear. - 1;
%put &VP.;

%let VYearChar = %sysfunc(putn(&Vyear, 4.));
%let Budget = "&VYearChar. Budget";
%let Actual = "&VYearChar. Actual";

%let V_Act = "&VP. Actual";

DATA Work.BotL;
Set WORK.Month_PYtoCYActuals;

Header = &V_Act.; MTD = 'PY Month Actual'n; OUTPUT;
Header = &Actual.; MTD = 'CY Month Actual'n; OUTPUT;
Header = 'Variance $'; MTD = '$ Variance'n; OUTPUT;

drop 'PY Month Actual'n;
drop 'CY Month Actual'n;
drop '$ variance'n;

RUN;


DATA Work.BotL;
Set WORK.Month_PYtoCYActuals;

Header = &V_Act.; MTD = 'PY Month Actual'n; OUTPUT;
Header = &Actual.; MTD = 'CY Month Actual'n; OUTPUT;
Header = 'Variance $'; MTD = '$ Variance'n; OUTPUT;

drop 'PY Month Actual'n;
drop 'CY Month Actual'n;
drop '$ variance'n;

RUN;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The SAS macro language is intended to generate text. As such it does not do any arithmetic unless you tell it to.

If the values you are working with are integer then you can use the %eval function to do the arithmetic (or logical comparisons):

 

%let vyear= 2024;
%let VP = %eval(&Vyear. - 1);
%put &VP.;

If your values involve decimals, i.e. floating point numbers, the function is %sysevalf, which has some options as the representation of the result so read up on it.

 

View solution in original post

2 REPLIES 2
ballardw
Super User

The SAS macro language is intended to generate text. As such it does not do any arithmetic unless you tell it to.

If the values you are working with are integer then you can use the %eval function to do the arithmetic (or logical comparisons):

 

%let vyear= 2024;
%let VP = %eval(&Vyear. - 1);
%put &VP.;

If your values involve decimals, i.e. floating point numbers, the function is %sysevalf, which has some options as the representation of the result so read up on it.

 

CSB35
Obsidian | Level 7
Thank you, this worked! My numbers are integers.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 597 views
  • 1 like
  • 2 in conversation