BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chrisjab
Fluorite | Level 6

I am trying to create a MTD flad on SAS EG to compare financial figures year over year; below is the formula I came up with, however I am not getting any answers. Not sure, what I'm doing wrong here:

 

CASE

WHEN MONTH(t1.TransactionDate) = MONTH (TODAY()) AND DAY(t1.TransactionDate) <= DAY(TODAY())

THEN 'MTD'

END

 

I have a list of TransactionsDates for 2015 (Jan to Dec) and 2016 YTD.

 

Thanks,

 

CJ 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Is TransactionDate a SAS Date or DateTime value. If it's DateTime then your When case would always be False.

View solution in original post

5 REPLIES 5
ballardw
Super User

Did you have an "END AS VaraibleName" ?

need to have a place to put the result

Kurt_Bremser
Super User
data have;
input transactiondate :yymmdd10.;
format transactiondate yymmddd10.;
cards;
2015-04-04
2015-10-02
2015-10-10
2016-04-04
2016-10-02
2016-10-10
;
run;

proc sql;
create table want as
select transactiondate,
case
when month(t1.TransactionDate) = month(today()) and day(t1.TransactionDate) <= day(today())
then 'MTD'
end as mtd
from have t1;
quit;

proc print noobs;
run;

delivers this result:

transactiondate    mtd

  2015-04-04          
  2015-10-02       MTD
  2015-10-10          
  2016-04-04          
  2016-10-02       MTD
  2016-10-10          

So to me, your query works as desired; if that is not the case with your code, post the complete SQL code and the log.

chrisjab
Fluorite | Level 6

Thank you Kurt, the problem was the date format

Patrick
Opal | Level 21

Is TransactionDate a SAS Date or DateTime value. If it's DateTime then your When case would always be False.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1635 views
  • 2 likes
  • 4 in conversation