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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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