DATA Step, Macro, Functions and more

case when understanding

Accepted Solution Solved
Reply
PROC Star
Posts: 633
Accepted Solution

case when understanding

[ Edited ]

Appreciate if some of you help me understand the meaning of the following case when statement.

 

case when upcase(DOMAIN)='NL' then '6131300'n 
     else '6231300'n 
end  as COMMISSION_AMT format=nlnum18.5

Accepted Solutions
Solution
‎02-28-2018 12:45 AM
Super User
Super User
Posts: 8,281

Re: case when understanding

Create a variable named COMMISSION_AMT whose value depends on the value of DOMAIN.  When DOMAIN has the value 'NL' then use the value from the '6131300'n variable otherwise use the value from the '6231300'n variable.  Attach the display FORMAT of NLNUM18.5 to the new variable.

View solution in original post


All Replies
Super User
Posts: 5,919

Re: case when understanding

You are not stating what it is you don't understand, but my guess the 

'6131300'n

stuff. It seem that you have source colunms with those names, hence the use of the n literal. Otherwise it would be interpreted as a string. 

Data never sleeps
PROC Star
Posts: 633

Re: case when understanding

yes, we've a source columns as follows. Could you please tell me what that case when statement will do?

 

'6131300'n
Super User
Posts: 10,588

Re: case when understanding

It either assigns the value of '6131300'n or '6231300'n (you should really get rid of such extremely stupid variable names three days before yesterday) to the newly created variable, depending on the condition.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 9,853

Re: case when understanding

The n after the string means the string is a named literal.  Named literals are used when dealing with poor data sources (such as Excell) where variable names are not compliant with SAS standards.  So in the case given variables cannot start with a number or special character, hence 6 is not a valid first character of a variable name.  To access these variables, the named literal is given and SAS internally converts this (or uses it) to access that data.

Whilst this is available and can be used to bring data into the SAS system, once it is in the SAS system it is highly recommended to give them SAS conformant variable names to remove this need for named literals. 

Solution
‎02-28-2018 12:45 AM
Super User
Super User
Posts: 8,281

Re: case when understanding

Create a variable named COMMISSION_AMT whose value depends on the value of DOMAIN.  When DOMAIN has the value 'NL' then use the value from the '6131300'n variable otherwise use the value from the '6231300'n variable.  Attach the display FORMAT of NLNUM18.5 to the new variable.

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 157 views
  • 4 likes
  • 5 in conversation