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

 

 

 

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
  • 19 replies
  • 11524 views
  • 1 like
  • 4 in conversation