Desktop productivity for business analysts and programmers

how to assign a variable value to an other variable under condition

Accepted Solution Solved
Reply
Regular Contributor
Posts: 168
Accepted Solution

how to assign a variable value to an other variable under condition

Hello,

 

I have a dataset with few variables.  4 of those (string variables) are:

 

createdby

policy_credit

quote_credit

txtype.

 

When txtype ne 'quote' I would like to take the value of creditedby and put it into policy_credit then set quote_credit to empty.

 

Data Soumweb1A;
set SoumWeb1;
if txtype eq 'policy' then policy_credit = updatedby;
run;

 

This code is note working, Why?


Accepted Solutions
Solution
‎02-07-2018 03:59 PM
Super User
Posts: 2,061

Re: how to assign a variable value to an other variable under condition

will this help?

if txtype ne quote_credit then do;
policy_credit=creditedby;
call missing(quote_credit);
end;

View solution in original post


All Replies
Solution
‎02-07-2018 03:59 PM
Super User
Posts: 2,061

Re: how to assign a variable value to an other variable under condition

will this help?

if txtype ne quote_credit then do;
policy_credit=creditedby;
call missing(quote_credit);
end;
Regular Contributor
Posts: 168

Re: how to assign a variable value to an other variable under condition

Posted in reply to novinosrin

I have try your code and it is not working

 

I have try the following

 

if txtype ne quote_credit then do;
policy_credit='test' ;
end;

and it works.  But for some reason I don't know, I am not able to assign the value of creditedby to policy_credit.

 

creditedby = 'aaa1234';

 

Any idea why.

 

Super User
Posts: 2,061

Re: how to assign a variable value to an other variable under condition

post a sample of your input data and your wanted output

Regular Contributor
Posts: 168

Re: how to assign a variable value to an other variable under condition

I have found my mistake.

 

Thanks!

Super User
Posts: 13,941

Re: how to assign a variable value to an other variable under condition

"Not working" is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

What is the value of the variable updatedby? What type is it (numeric or character) and what is its length? And why are you using it instead of creditedby (or possibly createdby)?

What type of variable is policy_credit (numeric or character) and what is its length?

What type of variable is creditedby (or is this supposed to be createdby) (numeric or character) and what is its length?

 

Types are important as numeric variables can't contain text. Text variables can be assigned values from numeric but the conversion may leave something to be desired depending on values and variable properties. If the text variable has a length of 3 and you try to stuff more characters into it from a longer variable the values will be truncated. With no error or warning.

 

I am assuming that you are actually using a value of "policy" that exists in your data variable txtype. Note that a policy number like 'abc123' is not equal to 'ABC123'.

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 176 views
  • 0 likes
  • 3 in conversation