Help using Base SAS procedures

Beginner Lvl Proc SQL date question

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Beginner Lvl Proc SQL date question

Quite simply I'm trying to write a case statement that will let me know if  date.B is 12 months older than date.A, then 'out of warranty'.  I used to writing it in DB2 like this

SQL NOEXEC;


SELECT

(case when t1.'''Warranty End date''n'n is null then ''

when t1.'''Warranty End date''n'n>t1.'''Purchase date''n'n+ 12 months then 'In Warrenty At Time of Call'

else '' end) AS CALCULATION

How do write this code in Proc SQL ?


Accepted Solutions
Solution
‎08-14-2014 10:37 AM
Super User
Super User
Posts: 7,401

Re: Beginner Lvl Proc SQL date question

Hi,

Something like:

proc sql;

     create table WANT as

     select     case     when WARRANTY_END_DATE is null then ''

                                when WARRANTY_END_DATE > intnx('MONTHS',PURCHASE_DATE,12) then "In warranty"

                                   else "" end as CALCULATION

     from      HAVE;

quit;

This assumes there is a dataset called HAVE with variables WARRANTY_END_DATE and PURCHASE_DATE, and that they are both already date format.

View solution in original post


All Replies
Solution
‎08-14-2014 10:37 AM
Super User
Super User
Posts: 7,401

Re: Beginner Lvl Proc SQL date question

Hi,

Something like:

proc sql;

     create table WANT as

     select     case     when WARRANTY_END_DATE is null then ''

                                when WARRANTY_END_DATE > intnx('MONTHS',PURCHASE_DATE,12) then "In warranty"

                                   else "" end as CALCULATION

     from      HAVE;

quit;

This assumes there is a dataset called HAVE with variables WARRANTY_END_DATE and PURCHASE_DATE, and that they are both already date format.

Occasional Contributor
Posts: 7

Re: Beginner Lvl Proc SQL date question

Thanks I see what I did wrong. It works.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 380 views
  • 0 likes
  • 2 in conversation