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

Dear all

Greetings of the day

 

i have to perform a arithmetical calculation repeated on the same dataset with the repeated variables from the year 2010 to 2018. 

my data set is as follows 

 

Var1_2010var2_2010var3_2010Var1_2011var2_2011var3_2011………….Var1_2018var2_2018var3_2018
21.21-1.4-19.81.55.732.1 59.821.16-8.9
5892.481807245.7824.61587712.8 7617.35786.812025.8
107.71-4.6-18.51.2 -1.6 22.64.9-5.9
206.1835.61.579.919.51082 651.6235.0651.4
1080.4-422.2113.9158.728.6845.4 1885.21103.55-755.9

 

I have to do the computation as follows

newvar_2010=var1_2010*0.345+var2_2010*0.657+var3*0.768

 

 

i have to repeat it for all the remaining years in the same way  from 2011 to 2018.

please suggest me a SAS code to do the calculation as mentioned above. 

 

thanks in advance. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Untested coz I was lazy to create sample data

 


data want;
 set have;
 array _constant(3) _temporary_ (0.345,0.657,0.768) ;
 array new(2010:2018) new2010-new2018;
 array t(2010:2018,3) var1_2010--var3_2018;
 do _i=2010 to 2018;
  do _j=1 to 3;
   new(_i)=sum(t(_i,_j)*_constant(_j),new(_i));
  end;
 end;
 drop _:;
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Untested coz I was lazy to create sample data

 


data want;
 set have;
 array _constant(3) _temporary_ (0.345,0.657,0.768) ;
 array new(2010:2018) new2010-new2018;
 array t(2010:2018,3) var1_2010--var3_2018;
 do _i=2010 to 2018;
  do _j=1 to 3;
   new(_i)=sum(t(_i,_j)*_constant(_j),new(_i));
  end;
 end;
 drop _:;
run;
PaigeMiller
Diamond | Level 26

@srikanthyadav44 wrote:

Dear all

Greetings of the day

 

i have to perform a arithmetical calculation repeated on the same dataset with the repeated variables from the year 2010 to 2018. 

my data set is as follows 

 

Var1_2010 var2_2010 var3_2010 Var1_2011 var2_2011 var3_2011 …………. Var1_2018 var2_2018 var3_2018
21.21 -1.4 -19.8 1.5 5.7 32.1   59.8 21.16 -8.9
5892.48 1807 245.7 824.6 158 7712.8   7617.3 5786.81 2025.8
107.71 -4.6 -18.5 1.2   -1.6   22.6 4.9 -5.9
206.18 35.6 1.5 79.9 19.5 1082   651.6 235.06 51.4
1080.4 -422.2 113.9 158.7 28.6 845.4   1885.2 1103.55 -755.9

 


Adding to the other replies ... this data structure is not a good one for most types of analyses, if you have created this data structure, the next time you might want to make it look like this:

 

Row VAR YEAR Value

1 var1 2010 21.21

1 var2 2010 -1.4

1 var3 2010 -19.8

2 var1 2010 5892.48

etc.

 

and the whole analysis of computing sums is extremely simple in PROC SUMMARY.

 

I realize that many times our data comes from Excel, and there it is organized as you showed in your original post, but if you are creating this data yourself, don't do it as in the original post, do it as I showed in this post.

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 968 views
  • 1 like
  • 4 in conversation