BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BU2B
Calcite | Level 5

Hey all,

 

I'm trying to subtract the values in two (identical) datasets using arrays.  Do I need to create a function, or can I do it with something like this?

 

data array1;
 set etrm_crep_va4;
 array array1 {24} HR0-HR23;
run;

 

data array2;
 set etrm_crep_va4_i;
 array array2 {24} HR0-HR23;
run;


/*Calculate the VA4 incremental difference*/

data etrm_crep_va4_inc;
array array1 {24} HR0-HR23;
array array2 {24} HR0-HR23;
 do i = 1 to 24;
  array1{i}-array2{i};
  output;
 end;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
slchen
Lapis Lazuli | Level 10

You could try this way.


data want;
   merge etrm_crep_va4  etrm_crep_va4_i(rename=(HR0-HR23=_HR0-_HR23));
   array array1 {24} HR0-HR23;
   array array2 {24} _HR0-_HR23;
   array array3 {24} Var0-Var23;
   do i = 1 to 24;
      array3{i}=array1{i}-array2{i};
      output;
   end;
run;

View solution in original post

3 REPLIES 3
Astounding
Opal | Level 21

Arrays never refer to two observations at the same time.  By definition, an array only refers to values within a single observation.

 

Your problem may still be possible to solve, but it will take more programming than that.

 

Do you have just one observation in each data set?  Otherwise, how do you know how to match the observations from one data set to the other?

slchen
Lapis Lazuli | Level 10

You could try this way.


data want;
   merge etrm_crep_va4  etrm_crep_va4_i(rename=(HR0-HR23=_HR0-_HR23));
   array array1 {24} HR0-HR23;
   array array2 {24} _HR0-_HR23;
   array array3 {24} Var0-Var23;
   do i = 1 to 24;
      array3{i}=array1{i}-array2{i};
      output;
   end;
run;

BU2B
Calcite | Level 5

Thanks guys!  I got that to work with a couple of tweeks...  I appreciate it!

 

Steve

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2295 views
  • 1 like
  • 3 in conversation