Pyrite | Level 9

## Get the minus value by multiplying amt column

Hi,

iam trying below code but iam getting amt column values as '0.00'.but i need the amt value to be -229 and 229 based on below conditions .

case when Sign='D'then Amt = (-1 * Amt ) else Amt
else when Sign='C' then Amt =(1 * Amt ) else Amt
For example if amt column holds 299 the if it is D then -299 and if it is C then amt should be 299

Amt

1 ACCEPTED SOLUTION

Accepted Solutions
Tourmaline | Level 20

## Re: Get the minus value by multiplying amt column

Loose the amt= part in your case statements and the last comma like this

``````proc sql;
create view work.W4J4UL3 as
select

(case when sign ='C' then -1 * Amt
else Amt
end) as Amt length = 8
format = 11.2
informat = 11.2,
(case when Sign1='C'
then (-1 * Amt1 )
else Amt1
end) as Amt1 length = 8
format = 11.2
informat = 11.2

from xxxx
;
quit;``````
11 REPLIES 11
Tourmaline | Level 20

Pyrite | Level 9

## Re: Get the minus value by multiplying amt column

Hi @PeterClemmensen ,please find below and kindly help

proc sql;
create view work.W4J4UL3 as
select

(case when sign ='C' then Amt = -1 * Amt
else Amt
end) as Amt length = 8
format = 11.2
informat = 11.2,
(case when Sign1='C'
then Amt1=(-1 * Amt1 )
else Amt1
end) as Amt1 length = 8
format = 11.2
informat = 11.2,

from xxxx
;
quit;

Super User

## Re: Get the minus value by multiplying amt column

``````data have;
input sign \$ amt;
datalines;
D 299
C 299
;

proc sql;
create table want as
select
sign,
case
when sign = 'C' then -amt
else amt
end as amt
from have;
quit;``````
Pyrite | Level 9

## Re: Get the minus value by multiplying amt column

Thanks @Kurt_Bremser .It is working as expected.i follow as you suggested,thanks

Tourmaline | Level 20

## Re: Get the minus value by multiplying amt column

Loose the amt= part in your case statements and the last comma like this

``````proc sql;
create view work.W4J4UL3 as
select

(case when sign ='C' then -1 * Amt
else Amt
end) as Amt length = 8
format = 11.2
informat = 11.2,
(case when Sign1='C'
then (-1 * Amt1 )
else Amt1
end) as Amt1 length = 8
format = 11.2
informat = 11.2

from xxxx
;
quit;``````
Pyrite | Level 9

## Re: Get the minus value by multiplying amt column

Thanks @PeterClemmensen and @Kurt_Bremser & @PaigeMiller .

i am getting what i expected in output.Thanks for quickly helping me on this

Diamond | Level 26

## Re: Get the minus value by multiplying amt column

The syntax for SQL (I assume this is what you are using, please confirm) does not use the equal sign after THEN

So you want

``````case when Sign='D' then -Amt
when Sign='C' then Amt end as Amt``````

--
Paige Miller
Pyrite | Level 9

## Re: Get the minus value by multiplying amt column

Thanks @PaigeMiller .Actually i should do soemthing like (-1 * Amt).you mean this is same as -Amt please.and can we not apply -1*amt ? please

Diamond | Level 26

## Re: Get the minus value by multiplying amt column

These should produce the same results.

--
Paige Miller
Pyrite | Level 9

## Re: Get the minus value by multiplying amt column

Diamond | Level 26

@JJP1 wrote: