Solved

SAS - Program a string variable containing a date

Posted on 2006-06-14
5
343 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

773 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