SAS - Program a string variable containing a date

Posted on 2006-06-14
Last Modified: 2010-04-17

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?

Question by:vadnick
  • 3
  • 2

Expert Comment

ID: 16903650
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);

. . .

TITLE1 Important Stuff Pertaining to  the Period:  &Pddata ;

Author Comment

ID: 16905525
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'

Accepted Solution

tobydavid earned 50 total points
ID: 16945329
Sorry for the delay, here is the code.  I could not find what you wanted as a standard SAS Format, so I created one with PROC FORMAT.

proc format;
Picture MyDate
  low-high='%d-%b-%Y%0y' (datatype=date);
data _null_;
date1 = put(date(),MyDate.);
date2 = put(date(),MyDate.);
call symput('PDData',"between '" || date1 || "' and '" || date2 || "'");
%put &pddata;


Author Comment

ID: 17177991
Thanks, that worked perfectly.  I'll have to study the code to see how it works.

Expert Comment

ID: 17178049
You are welcome.  Let me know if you have any questions.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to split this in C++ 4 94
groupSumClump challenge 9 102
mapBully challenge 6 115
creating threads in delphi 1 82
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now