Exploring, predicting and reporting with SAS Visual Analytics and SAS Visual Statistics

Add New Column based on IF Statement

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Add New Column based on IF Statement

Hi, I am very new to SAS Visual Analytics and I am having problems creating a new Column where I have to use an If Then Else Statement.

The context is: I created a query in design mode with multiple tables. I noticed that we cannot use the Conditional statement in expression clause. How can I create a column with IF Then Else?

 

These Two Columns exist already

ResolvedTeam         ProductResposibleTeam

A                                              X

A                                              Z

B                                              P                     

C                                              O        

A                                              O

C                                              P         

D                                              W

What I need is: A new column where I combine two fields under the condition: if resolved by A then return the RroductResponsibleTeam if not return the ResolvedTeam.

What I need as an output is:

NewColumn

X

Z

B

C

O

C

D

 

Please help with as much details as possible as I am new to the tool. Thanks in advance.

 


Accepted Solutions
Solution
‎08-17-2016 01:59 PM
Regular Contributor
Posts: 197

Re: Add New Column based on IF Statement

Hello,

 

in SAS VA,

 

IF ( 'ResolvedTeam'n In ('A') )
RETURN ' ProductResposibleTeam'n
ELSE 'ResolvedTeam'n

 

 

Let me know.

 

 

Thanks & Regards,

Teja Surapaneni

View solution in original post


All Replies
Trusted Advisor
Posts: 1,228

Re: Add New Column based on IF Statement

Hi,

 

Please try this:

 

data want;
set have;
NewColumn=ResolvedTeam;
if ResolvedTeam='A' then NewColumn=ProductResposibleTeam;
run;

Occasional Contributor
Posts: 5

Re: Add New Column based on IF Statement

Here is the error I am getting:

SAS error.png

Trusted Advisor
Posts: 1,228

Re: Add New Column based on IF Statement

Data set "have" would be based on information provided. I've added syntax to create data set. Please try this:

 

data have;
input ResolvedTeam $ ProductResposibleTeam $;
datalines;
A  X
A  Z
B  P
C  O
A  O
C  P
D  W
;

 

data want;
set have;
NewColumn=ResolvedTeam;
if ResolvedTeam='A' then NewColumn=ProductResposibleTeam;
run;

Occasional Contributor
Posts: 5

Re: Add New Column based on IF Statement

The code works but the column is not created. Why?

Thanks again.

 

Super User
Posts: 5,387

Re: Add New Column based on IF Statement

Another option is to create the column in the Visual Data Builder. There you use SQL syntax, which means that you can use CASE-WHEN-THEN-ELSE-syntax.
Data never sleeps
Solution
‎08-17-2016 01:59 PM
Regular Contributor
Posts: 197

Re: Add New Column based on IF Statement

Hello,

 

in SAS VA,

 

IF ( 'ResolvedTeam'n In ('A') )
RETURN ' ProductResposibleTeam'n
ELSE 'ResolvedTeam'n

 

 

Let me know.

 

 

Thanks & Regards,

Teja Surapaneni

Occasional Contributor
Posts: 5

Re: Add New Column based on IF Statement

I really don’t know how it works. There is no error but nothing is happening as an output. Is there anything to do with libraries?

 

Thanks again.

 

Occasional Contributor
Posts: 5

Re: Add New Column based on IF Statement

Thank you so much.

☑ This topic is solved.

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

Discussion stats
  • 8 replies
  • 1260 views
  • 6 likes
  • 4 in conversation