BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

Hello Experts,

 

I would like to replace the . value using the case statement, but it doesn't work, I have the 01/01/1960 in the place of . value.

My code is :

proc sql;
	create table Donnees as 
   select  c.cd_rga
         , b.is_support
         , c.lb_court
         , b.d_fin
         , a.mt_ea,
	      , sum(a.mt_ea) as total	
	from SUPPORT as a

   left join (select is_support,
    case d_fin when . then d_fin="31DEC2023"d else d_fin
             end as d_fin format ddmmyy10.
              from RGA
              group by is_support
              having 
              or max(b.d_fin) = b.d_fin)  as b
   on a.is_support = b.is_support

	left join RGPC as c 
   on b.is_rga=c.is_rga

	where a.s_type_support="OK"
	group by c.cd_rga
	;
quit;

Thank you for your help !

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you are seeing dates of 01JAN1960 then the value is ZERO and not missing (or NULL as SQL would call it).

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

If you are seeing dates of 01JAN1960 then the value is ZERO and not missing (or NULL as SQL would call it).

SASdevAnneMarie
Barite | Level 11
Hi Tom,
Sorry, I accepted the answer but the code still not work. When I put in « when 0 »
I don’t have 01/01/1960 any more, I obtain only the points. I suppose that my case statement doesn’t work.
Tom
Super User Tom
Super User

You should be able to debug yourself by executing the different parts in simpler queries.

 

Here are two obvious things:

case d_fin
  when . then d_fin="31DEC2023"d 
  else d_fin
end as d_fin format ddmmyy10.

Will set the calculated D_FIN variable ZERO when it is missing because MISSING does not equal the last day of 2023 and SAS returns a ZERO when a boolean expression like your equality test is FALSE.

 

This HAVING clause looks suspect.  

having or max(b.d_fin) = b.d_fin

OR is binary operator, it needs TWO arguments and you have only given it one.

What did you intend here?

SASdevAnneMarie
Barite | Level 11
I see : then d_fin="31DEC2023"d is not correct, I must write then "31DEC2023"d and it's work.
Tom
Super User Tom
Super User

Or just use the SQL function COALESCE() instead of CASE construct. 

This is exactly the type of situation that function is designed for.

coalesce(d_fin,"31DEC2023"d)

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1524 views
  • 1 like
  • 2 in conversation