Contributor
Posts: 39

# Diff in Arrays

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

 102 50 100 150 200 62.5 125 187.5 250 5 104 60 100 120 180 75 125 150 225 5 106 80 130 160 220 100 162.5 200 275 5
PROC Star
Posts: 1,405

## Re: Diff in Arrays

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

Contributor
Posts: 39

## Re: Diff in Arrays

yes same as qtr1m qtr2m qtr3m qtr4m

Super User
Posts: 9,862

## Re: Diff in Arrays

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.

Contributor
Posts: 39

## Re: Diff in Arrays

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

Super User
Posts: 10,600

## Re: Diff in Arrays

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 39

## Re: Diff in Arrays

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
Super User
Posts: 9,862

## Re: Diff in Arrays

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;

Discussion stats
• 7 replies
• 198 views
• 0 likes
• 4 in conversation