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);

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1235 views
  • 0 likes
  • 4 in conversation