Getting values from Date_range Prompt using do-while

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Getting values from Date_range Prompt using do-while

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

 


Accepted Solutions
Solution
‎09-26-2016 05:32 AM
Valued Guide
Posts: 2,177

Re: Getting values from Date_range Prompt using do-while

Try
%while( %sysevalf("&temp"d<"&limit"d) )

The sysevalf() function will cope with converting date constants

View solution in original post


All Replies
Super User
Posts: 7,371

Re: Getting values from Date_range Prompt using do-while

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎09-26-2016 05:32 AM
Valued Guide
Posts: 2,177

Re: Getting values from Date_range Prompt using do-while

Try
%while( %sysevalf("&temp"d<"&limit"d) )

The sysevalf() function will cope with converting date constants
New Contributor
Posts: 2

Re: Getting values from Date_range Prompt using do-while

Tnx Peter_C,
this is what i was looking for..
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 358 views
  • 2 likes
  • 3 in conversation