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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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