Desktop productivity for business analysts and programmers

How to change the value of single cells (of a column) based on some conditions (of other columns)?

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

How to change the value of single cells (of a column) based on some conditions (of other columns)?

Say I have the following data:

 

Var1   Var2   Var3

0         0        1

1         1        3

0         1        1
0         0        1

1         1        1

 

How can I change values in Var3 to "-999" if Var1=1 and Var2=1?


Accepted Solutions
Solution
‎07-19-2017 01:35 PM
PROC Star
Posts: 1,167

Re: How to change the value of single cells (of a column) based on some conditions (of other columns

Yes, it's quite easy in EG. Create a new query, and create an advanced expression. In the advanced expression, the CASE function will let you implement "if then else" type logic.

 

 

View solution in original post


All Replies
Contributor
Posts: 23

Re: How to change the value of single cells (of a column) based on some conditions (of other columns

You would want to use if-else conditions. Note that the -999 will be numeric since I assume that is what you want.

 

data want;
set have;
if Var1=1 and Var2=1 then Var3 = -999;
run;

 

Source:

https://v8doc.sas.com/sashtml/lgref/z0202239.htm

Contributor
Posts: 23

Re: How to change the value of single cells (of a column) based on some conditions (of other columns

Thanks, I understand the SAS base code that can do that, but since it's in Enterprise Guide, does it not have a point-and-click solution to it?

Solution
‎07-19-2017 01:35 PM
PROC Star
Posts: 1,167

Re: How to change the value of single cells (of a column) based on some conditions (of other columns

Yes, it's quite easy in EG. Create a new query, and create an advanced expression. In the advanced expression, the CASE function will let you implement "if then else" type logic.

 

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 218 views
  • 0 likes
  • 3 in conversation