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.0 | 187.5 | 250 | 5 |
104 | 60 | 100 | 120 | 180 | 75.0 | 125.0 | 150.0 | 225 | 5 |
106 | 80 | 130 | 160 | 220 | 100.0 | 162.5 | 200.0 | 275 | 5 |
How do you want the differences presentes? In seperate columns? 🙂
yes same as qtr1m qtr2m qtr3m qtr4m
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.
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
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.
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;
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!
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.