BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alpod87
Calcite | Level 5

Hi!

I have 2 columns with ratings A-K. One column is "incoming" rating (IB) of a period and the other "outgoing" (OB).

 

I'm looking to create a new column based on several conditions:

0 if no change during the period

1 if moved up 1 class, 2 if moved up 2 classes etc

-1 if moved down 1 class, 2 if moved down 2 classes etc

 

How would one go about accomplishing this without creating one hundred case when lines?

 

Thank you very much 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I'm looking to create a new column based on several conditions:

0 if no change during the period

1 if moved up 1 class, 2 if moved up 2 classes etc

-1 if moved down 1 class, 2 if moved down 2 classes etc

 

How would one go about accomplishing this without creating one hundred case when lines?

 

Create new variables where the letters A, B, ... K are replaced by numbers and then the moving up or moving down is computed by subtraction. You can use the RANK function to obtain the numerical equivalent of A, B, ... K in the ASCII collating sequence; that's all you need.

 

data want;
    set have;
    ib_rank=rank(ib);
    ob_rank=rank(ob);
    change=ob_rank-ib_rank;
run;

  

--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26

I'm looking to create a new column based on several conditions:

0 if no change during the period

1 if moved up 1 class, 2 if moved up 2 classes etc

-1 if moved down 1 class, 2 if moved down 2 classes etc

 

How would one go about accomplishing this without creating one hundred case when lines?

 

Create new variables where the letters A, B, ... K are replaced by numbers and then the moving up or moving down is computed by subtraction. You can use the RANK function to obtain the numerical equivalent of A, B, ... K in the ASCII collating sequence; that's all you need.

 

data want;
    set have;
    ib_rank=rank(ib);
    ob_rank=rank(ob);
    change=ob_rank-ib_rank;
run;

  

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 602 views
  • 3 likes
  • 2 in conversation