SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Formats for negative values

Reply
Super Contributor
Posts: 625

Formats for negative values

I'm creating one variable called 'VBHTO' in target dataset DI studio and it was coming from the variable AMT from source dataset. Now I was asked to convert any positive values from the variable  'VBHTO' to negative value. e.g. if VBHTO is 40 then should be converted to -40. 

 

I've added the following condition under 'Expression' earlier. Format of this variable is 18.2.

 

case when CLAIM_AMT_TYPE_CD='2'  and SUBTYPE_CD='2' then AMT
end

Now when I modify the same condition as below to incorporate the new changes, I was not seeing any changes in the output. Appreciate if someone of you help me with the solution and to tackle this issue. 

 

case when CLAIM_AMT_TYPE_CD='2'  and SUBTYPE_CD='2' then AMT=-AMT
end

 

Super User
Super User
Posts: 9,456

Re: Formats for negative values

[ Edited ]

Thats not how an SQL statement is made.  You may want to read up on how to create SQL statements, as that is a basic mistake using SAS syntax in SQL:

case when claim_amt_type_cd='2' and subtype_cd='2' then -amt else amt end as amt

I.e. 


case
 when <condition or value> then <value> when <condition or value> then <value>
else <value>
end as <variable>

 

Forum seems broken again, can't use two code blocks!


Edit (KB): I managed to put your second example into a code window; might be your browser?

Super Contributor
Posts: 625

Re: Formats for negative values

[ Edited ]

It's not working. I used the following code in expression, and the job was successful but it failed to convert it to negative values.

 

 

Super User
Super User
Posts: 9,456

Re: Formats for negative values

No code provided.  No test data provided.  "It's not working" - tells us nothing.  This does work:

data have;
  a=3;
run;

data want;
  set have;
  b=-a;
run;

So what is it your doing which is not working?

Respected Advisor
Posts: 4,702

Re: Formats for negative values


@Babloo wrote:

It's not working. I used the following code in expression, and the job was successful but it failed to convert it to negative values.

 

 


@Babloo

Then most likely your condition is not working as you believe and it got never TRUE. If you just want to test that the condition works then use something like 1=1 as condition and then test what you get for AMT.

Ask a Question
Discussion stats
  • 4 replies
  • 168 views
  • 1 like
  • 3 in conversation