Solved

SAS - Program a string variable containing a date

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
fix34  challenge 9 97
VBA color chart bars 12 66
array6 challenfge 6 63
array11 challenge 16 51
Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
This is about my first experience with programming Arduino.
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…

758 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

23 Experts available now in Live!

Get 1:1 Help Now