Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting Beginning and Ending Date, last year, in SAS

Posted on 2014-03-14
6
Medium Priority
?
531 Views
Last Modified: 2016-02-10
I need to create 'put' statements in order to get '01/01/previous year' and '12/31/previous year' for a program that is run on an annual basis so I don't need to manually change the year.

My sql code in the proc sql is this:
      AND EFF_DT <= '12/31/2013'
      AND (TRM_DT BETWEEN '01/01/2013' AND '12/31/2013'
            OR TRM_DT IS NULL)

This is also inside a macro and I'm not sure once I get the dates for the 'put' statement, what I need to change the hard coded dates to in order for the query to work.
0
Comment
Question by:Lee R Liddick Jr
  • 3
  • 2
6 Comments
 
LVL 11

Accepted Solution

by:
theartfuldazzler earned 1400 total points
ID: 39929057
Hi

the INTNX function is the one you want:


INTNX("year", TODAY() , -1, 'B')
INTNX("year", TODAY() , -1, 'E')

Will give you the "B"eginning of the previous year and the "E" of the previous year
0
 

Author Comment

by:Lee R Liddick Jr
ID: 39929125
Not sure how to get this to function properly within my script though?  I just get an error:
ERROR: CLI describe error:  SQL0180N  The syntax of the string
       representation of a datetime value is incorrect.  

/*** GET PREVIOUS YEAR DATES ***/
data _null_;
      today = today();
      begdate = INTNX("year", TODAY() , -1, 'B');
      enddate = INTNX("year", TODAY() , -1, 'E');
      put begdate :date9.;
      put enddate :date9.;
run;
/* in the query */
      AND EFF_DT <= '&enddate'
      AND (TRM_DT BETWEEN '&begdate' AND '&enddate'
            OR TRM_DT IS NULL)
0
 
LVL 14

Assisted Solution

by:Aloysius Low
Aloysius Low earned 600 total points
ID: 39929192
remove the quotation marks enclosing &enddate and &begdate should solve the problem.. that's because a single quotation mark treats the macro variable as a literal text while a double quotation mark causes the macro variable value into a string, which isn't valid here
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Lee R Liddick Jr
ID: 39929257
Something else is going on.  It's inside a macro so I'm not sure if I set the values within the macro too?  No matter how I do it, I can't get it to process.

%macro hcx(st,rgn,dsname,file);

      AND EFF_DT <= &enddate
      AND (TRM_DT BETWEEN &begdate AND &enddate
            OR TRM_DT IS NULL)

%hcx(TX,%str(AND RGN_C = '1'),ctx,%str(filename) );
%hcx(FL,%str(AND RGN_C = '1'),cfl,%str('filename') );
0
 
LVL 14

Assisted Solution

by:Aloysius Low
Aloysius Low earned 600 total points
ID: 39929334
to see what the macro is executing, execute the following code first:
options mprint;

to see what values the variables translate to, execute the following code first:
options symbolgen;

these should greatly help in the debugging process... at the moment with what was posted, it's almost impossible to help in troubleshooting...
0
 

Author Comment

by:Lee R Liddick Jr
ID: 39929466
That was perfect.  Found exactly what I was doing wrong and corrected.  Thank you so much!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

877 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