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

Beginner here.

 

I am trying to create a set of numerical values in a SAS macro with the %let command. The idea is to slice a SQL query that is giving me an overrun error (too much data that goes over the 32GB size limit) into manageable pieces and paste them back together at the end. The code is simple:

 

%let days2get = 200;


%macro pulldata;
%do i = 1 %to 20;
%let days&i = &i*10;
%put "&&days&i";
%end;
%mend pulldata;
%pulldata

 

Then the SQL query will include 

 

WHERE gp.gen_date > SYSDATE - &&days&i - 10

AND gp.gen_date < SYSDATE - &days&i

 

The problem is that the output appears to not be numerical but stored as a character: The output log is:

 

27 %let days2get = 200;
28
29
30
31 %macro pulldata;
32 %do i = 1 %to 20;
33 %let days&i = &i*10;
34 %put "&&days&i";
35 %end;
36 %mend pulldata;
37 %pulldata


"1*10"
"2*10"
"3*10"
"4*10"
"5*10"
"6*10"
"7*10"
"8*10"
"9*10"
"10*10"
"11*10"
"12*10"
"13*10"
"14*10"
"15*10"
"16*10"
"17*10"
"18*10"
"19*10"
"20*10"

 

How do I force these to be numerical?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The %PUT statement writes out characters in quotes, because you added quotes in the %PUT statement.  These are different:

 

%put "&&days&i";

 

%put &&days&i;

 

As was noted, to get math to be computed, you need to apply a function.  Easiest:

 

%let days&i = %eval(&i * 10);

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Are you after this?

 

%let days2get = 200;


%macro pulldata;
%do i = 1 %to 20;
%let days&i = %sysevalf(&i*10);/*correction*/
%put "&&days&i";
%end;
%mend pulldata;
%pulldata
ballardw
Super User

Note: Macro variables are always text. In context of created SAS statements they may be used as, and resolve as, numeric but the actual variable is text.

Astounding
PROC Star

The %PUT statement writes out characters in quotes, because you added quotes in the %PUT statement.  These are different:

 

%put "&&days&i";

 

%put &&days&i;

 

As was noted, to get math to be computed, you need to apply a function.  Easiest:

 

%let days&i = %eval(&i * 10);

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
  • 3 replies
  • 1282 views
  • 0 likes
  • 4 in conversation