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

Hi,

I've created Date_range Prompt named "range".

My goal is to reach values between range_min and range_max using do while loop in macro. I can get values using intnx function inside data step, but i want to use values in several data steps and proc sql's in macro.

Here is the shorter version of my code and the problem is that my code doesn't stop at value of range_max:

%_eg_conditional_dropds(WORK.base_all);

%macro radi;

%let temp=&range_min;
%let limit=&range_max;

%put temp=&temp;
%put limit=&limit;

%do %while("&temp"d<"&limit"d);

%_eg_conditional_dropds(WORK.test);
data test;
format now limit date9.; 
now=intnx('day',"&temp"d,1);
limit="&limit"d;
call symput('temp', put(now,date9.));
run;

proc append base=work.base_all data=test; quit;

%end;
%mend;

%radi

Example: if i want date range between 01Sep2016 and 30Sep2016, this program stops at 31Oct2016.

I use SAS EG 7.1

 

1 ACCEPTED SOLUTION

Accepted Solutions
Peter_C
Rhodochrosite | Level 12
Try
%while( %sysevalf("&temp"d<"&limit"d) )

The sysevalf() function will cope with converting date constants

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

The macro language is a text processing language, and comparisons will be text comparisons, meaning that the string "02jan2016"d will be considered "bigger" than "01may2016"d!

 

You would be better off if you stored the raw date values (days from 01jan1960) with format z5. (creating leading zeroes) into your "macro date" variables.

Another trick would be to create a list of dates in a data step, and use call execute to call a macro doing the work for each date.

Peter_C
Rhodochrosite | Level 12
Try
%while( %sysevalf("&temp"d<"&limit"d) )

The sysevalf() function will cope with converting date constants
tino86
Fluorite | Level 6
Tnx Peter_C,
this is what i was looking for..

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
  • 3 replies
  • 835 views
  • 2 likes
  • 3 in conversation