BookmarkSubscribeRSS Feed
Ravikumarpa4
Obsidian | Level 7

hi how to find diiference for below data using arrays

need diff between qtr1-qtr1n.. so on..

 

Obs id qtr1 qtr2 qtr3 qtr4 Qtr1n Qtr2n Qtr3n Qtr4n i 1 2 3

1025010015020062.5125.0187.52505
1046010012018075.0125.0150.02255
10680130160220100.0162.5200.02755
7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

How do you want the differences presentes? In seperate columns? 🙂

Ravikumarpa4
Obsidian | Level 7

yes same as qtr1m qtr2m qtr3m qtr4m

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep, we are not here for data entry!

 

Something like:

data want;
  set have;
  array qtr{4};
  array qtr2{4} qtr1n qtr2n qtr3n qtr4n;
  array res{4};
  do i=1 to 4;
    res{i}=qtr2{i}-qtr{i};
  end;
run;

Why have you called array elements qtrXn, that just makes your programming harder, put the number at the end.

Ravikumarpa4
Obsidian | Level 7

 

below is my original data set;

first I need increasing qtr value to 25% later i wanted difference between both by using arrays. kould you help on this

id qtr1 qtr2 qtr3 qtr4;

102 50 100 150 200

104 60 100 120 180

106 80 130 160 220

 

Kurt_Bremser
Super User

For those who have a hard time grasping the concept, this is how you post data in a data step:

data have;
input id qtr1 qtr2 qtr3 qtr4;
cards;
102 50 100 150 200
104 60 100 120 180
106 80 130 160 220
;
run;

Now all possible helpers only need a copy/paste and "run" to recreate your dataset. Be courteous to those who shall help you.

Ravikumarpa4
Obsidian | Level 7
##- Please type your reply above this line. Simple formatting, no
attachments. -##
Hi
That's I've done it already. Now I'm wanted increase values by 25% and
later I wanted find difference between both by using Arrays

Regards
Ravi
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like (again, not typing in):

data want;
  set have;
  array qtr{4};
  array qtr2{4};
  array res{4};
  do i=1 to 4;
    qtr2{i}=1.25 * qtr{1};
    res{i}=qtr2{i}-qtr{i};
  end;
run;

However this doesn't make much sense as diff will always be 25% so why the need for the second set of variables at all, just do:

res{i}=(qtr{i} / 100) * 25;

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
  • 7 replies
  • 2151 views
  • 0 likes
  • 4 in conversation