BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

@sufiya wrote:

question, if I wanted to combine 2 months together like October & November  - is that possible? using the Case.

thank you again! 

case month(Date_Bought) when 10 and 11 then Bought
        end as Date_Bought_OctDec

 


You can use a CASE statement, but not in that way.  That statement is looking for data bought in January, not October or December. '10 and 11' is an boolean expression. Since both 10 and 11 are not zero then it is always true so it has a value of 1.

 

You can either use two WHEN clauses 

case month(Date_Bought)
 when 10 then Bought
 when 12 then Bought
end as Date_Bought_OctDec

Or put the test in the WHEN clause.

case when month(Date_Bought) in (10,11) then Bought
end as Date_Bought_OctDec

 

sufiya
Quartz | Level 8

thank you @Tom that worked too! 

 

Question, what logic is needed to insert zero '0' into the blank rows/variables? 

tried adding the following to CASE, 

else if column=. then column=0 end as October

but receiving an error. please help .... 

Reeza
Super User

IF isn't valid in SQL, try replacing it with WHEN instead.

sufiya
Quartz | Level 8

Thank you!  worked with when and not if

sufiya
Quartz | Level 8

question, if I wanted to combine 2 months together like October & November  - is that possible? using the Case.

thank you again! 

 

 

case month(Date_Bought) when 10 and 11 then Bought
        end as Date_Bought_OctDec

 

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 19 replies
  • 15284 views
  • 1 like
  • 4 in conversation