?
Solved

SAS - Program a string variable containing a date

Posted on 2006-06-14
5
Medium Priority
?
375 Views
Last Modified: 2010-04-17
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!
0
Comment
Question by:vadnick
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:tobydavid
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);
run;

. . .

TITLE1 Important Stuff Pertaining to  the Period:  &Pddata ;
0
 

Author Comment

by:vadnick
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'
...
0
 
LVL 4

Accepted Solution

by:
tobydavid earned 200 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 || "'");
run;
%put &pddata;



0
 

Author Comment

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

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes
Suggested Courses

752 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