Dear all,
how can I compare new_variable with the old_variable and show whether they have been changed( create a notification variable, say '1' if the new_variable is different from the old_variable, say '0' if both variables are the same.) The variables are different when they are the same word but different case.
for example, I expect to get the following result,
old_variable new_variable notification
apple Apple 1
juice juice 0
Original Original 0
mango nango 1
data have;
length
old_variable $20
new_variable $20 ;
input
old_variable
new_variable ;
cards;
apple Apple
juice juice
Original Original
mango nango
;
run;
Could you please give me some suggestions about this?
thanks in advance
A simple comparison between the variables should do.
data have;
length
old_variable $20
new_variable $20;
input
old_variable
new_variable;
change_flag= (old_variable ne new_variable);
cards;
apple Apple
juice juice
Original Original
mango nango
;
run;
What below line does:
change_flag= (old_variable ne new_variable);
old_variable ne new_variable -
Expression to compare the content in the two variables. The expression returns 1 (TRUE) if there is a difference and 0 (FALSE) if there is no difference
change_flag=
Variable to assign the result to from the result of the expression to the right of the equal sign.
A simple comparison between the variables should do.
data have;
length
old_variable $20
new_variable $20;
input
old_variable
new_variable;
change_flag= (old_variable ne new_variable);
cards;
apple Apple
juice juice
Original Original
mango nango
;
run;
What below line does:
change_flag= (old_variable ne new_variable);
old_variable ne new_variable -
Expression to compare the content in the two variables. The expression returns 1 (TRUE) if there is a difference and 0 (FALSE) if there is no difference
change_flag=
Variable to assign the result to from the result of the expression to the right of the equal sign.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.