BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Alexxxxxxx
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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.

 

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

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.

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 556 views
  • 1 like
  • 2 in conversation