Solved

SAS - Program a string variable containing a date

Posted on 2006-06-14
5
365 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 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 || "'");
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 Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Starting up a Project

691 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