Link to home
Start Free TrialLog in
Avatar of vadnick
vadnick

asked on

SAS - Program a string variable containing a date

Hello,

I'm pretty new to SAS programming, so forgive me if this question is pretty green...

I want to do something like this:

%let pddata = between '01-jan-2005' and '31-dec-2005';

However, I want to do this so that it generates this variable dynamically using date functions.

Any ideas?

Thanks!
Avatar of tobydavid
tobydavid

To dynamically get information into a SAS Symbol like &pddata, use the SYMPUT Function

as in the following:

Data _null_;
date1 = ...
date2 = ...
call Symput('Pddata','between ' || date1 || ' and ' || date2);
run;

. . .

TITLE1 Important Stuff Pertaining to  the Period:  &Pddata ;
Avatar of vadnick

ASKER

Would you be able to write the exact code?  

With my original statement, I can have a line in a proc sql that reads

...
where a.date_of_purchase &pddata
...

Expanded, this is interpretted as

...
where a.date_of_purchase between '01-JAN-2005' and '12-31-2005'
...

So far, I'm able to get the dynamic code to return the following:

...
where a.date_of_purchase between '       16437' and '       16801'
...
ASKER CERTIFIED SOLUTION
Avatar of tobydavid
tobydavid

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vadnick

ASKER

Thanks, that worked perfectly.  I'll have to study the code to see how it works.
You are welcome.  Let me know if you have any questions.