DATA Step, Macro, Functions and more

want to output Y if observations variable x equals to something

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

want to output Y if observations variable x equals to something

Hi

 

I want to output "Y" if FIN_CD equals "1S". If there's any other variable other than 1S then I do not want to output them. I'm not sure if I'm able to do this in the WHERE statement or if I need a data step.

 

Here is some sample code:

 

PROC SQL;
create table automation_exception as

SELECT
TRANSACTION_FACT.TRN_CD as FIN_CD,
FROM RDWP0.TRANSACTION_FACT, RDWP0.TRANSACTION_CD_LOOKUP, WHERE (TRANSACTION_CD_LOOKUP.TRN_CD=TRANSACTION_FACT.TRN_CD) AND (ACCT_DIM.ACCT_ID=TRANSACTION_FACT.ACCT_ID);

QUIT;

Accepted Solutions
Solution
‎01-23-2017 09:42 AM
Super Contributor
Posts: 474

Re: want to output Y if observations variable x equals to something

Posted in reply to jmoore168

Hi.

 

 

Could it be as simple as the following?

 

 


SELECT  
  case when TRANSACTION_FACT.TRN_CD eq '1S' then '1S' else 'N' end as FIN_CD,
       
  

 

Daniel Santos @ www.cgd.pt

 

View solution in original post


All Replies
Super User
Posts: 11,343

Re: want to output Y if observations variable x equals to something

Posted in reply to jmoore168

jmoore168 wrote:

Hi

 

I want to output "Y" if FIN_CD equals "1S". If there's any other variable other than 1S then I do not want to output them. I'm not sure if I'm able to do this in the WHERE statement or if I need a data step.

 


Did you mean if FIN_CD is not equal to '1S' you don't want them in the output at all? If so subset the data as early as practical:

 

FROM

(select * from RDWP0.TRANSACTION_FACT where TRN_CD = '1S') ,

RDWP0.TRANSACTION_CD_LOOKUP,

 

will only select the records of interest before combining with the other data set.

Occasional Contributor
Posts: 9

Re: want to output Y if observations variable x equals to something

Hi Ballardw

Your solution worked perfectly. However I may have been mistaken with regard to how I want to handle other FIN_CD's separately from 1S. For example if FIN_CD output's anything other than '1S' then I want it to output blank or 'N'. This blank tells us we need to take a specific action. 1S means we have already did it. Basically this is an exception report. I need to combine the previous code you sugguested in addition to what I'm asking here.

Hope this helps.
Solution
‎01-23-2017 09:42 AM
Super Contributor
Posts: 474

Re: want to output Y if observations variable x equals to something

Posted in reply to jmoore168

Hi.

 

 

Could it be as simple as the following?

 

 


SELECT  
  case when TRANSACTION_FACT.TRN_CD eq '1S' then '1S' else 'N' end as FIN_CD,
       
  

 

Daniel Santos @ www.cgd.pt

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 134 views
  • 1 like
  • 3 in conversation