BookmarkSubscribeRSS Feed
sandhya88
Calcite | Level 5

Here is how my sample data looks like

ID$ Tst$ test_rt number

1    dp    20          1

1    rp     0            1

1    dp    35          2

1    rp     20          2

1    dp     0           3

1    rp      20         3

 

I would like to have an algorithm setup for calculating the difference between dp at number 1 and rp at value at next number?? Did any one encounter such situations, If so how to tackle that?? Please suggest, Thanks in advance

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

Please try

 

data have;
input ID$ Tst$ test_rt number;
cards;
1 dp 20 1
1 rp 0 1
1 dp 35 2
1 rp 20 2
1 dp 0 3
1 rp 20 3
;

 
data want;
set have;
by number notsorted;
retain new_number;
if first.number then new_number=test_rt;
if last.number then dif=test_rt -new_number;
run;
Thanks,
Jag
mkeintz
PROC Star

By

 


"difference between dp at number 1 and rp at value at next number".


I think you want the rp test value minus the dp test value for each number.  If so, then:

 

data want;
  merge  have (where=(tst='dp') rename=test_rt=dp_test)
         have (where=(tst='rp') rename=test_rt=rp_test);
  by number;
  rp_minus_dp=rp_test-dp_test;
  drop tst ;
  if last.number;
run;

If that's not what you mean, please show what the results would look like for the data you provided.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 2 replies
  • 912 views
  • 1 like
  • 3 in conversation