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

I have following data

 

Descriptionnumber_1number_2number_3total
Quantity1236
Value10203060
     
I want to create    
Descriptionnumber_1number_2number_3total
Total ammount (quantity*value)104090360

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Do you have IML ? it is easy for IML.

 

data have;
input Description $	number_1	number_2	number_3	total;
cards;
Quantity	1	2	3	6
Value	10	20	30	60
;

proc iml;
use have;
read all var _num_ into x[c=vname];

Description='Total ammount';
want=x[#,];
create want from want[c=vname r=Description];
append from want[r=Description];
close;
quit;


proc print;run;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

This horizontal layout is a very poor choice for such a data set, and a long data set would make the programming easier. So, let's create a long data set, and then the calculations are trivial.

 

data have;
    input Description $	number_1	number_2	number_3	total;
    cards;
Quantity	1	2	3	6
Value	10	20	30	60
;

proc transpose data=have out=have_t;
    id description;
run;

data want;
    set have_t;
    total_amount=quantity*value;
run;

 

Hint: don't arrange your data in wide data sets if at all possible. Arrange your data in long data sets (such as data set HAVE_T in the code above) whenever possible, this make the programming much easier in most cases. See Maxim 19

--
Paige Miller
Ksharp
Super User

Do you have IML ? it is easy for IML.

 

data have;
input Description $	number_1	number_2	number_3	total;
cards;
Quantity	1	2	3	6
Value	10	20	30	60
;

proc iml;
use have;
read all var _num_ into x[c=vname];

Description='Total ammount';
want=x[#,];
create want from want[c=vname r=Description];
append from want[r=Description];
close;
quit;


proc print;run;