Hello, expert, I have a matrix
ID | col2 | col3 | col4 |
1 | 0.2543 | 0.376363 | 0.306857 |
2 | 0.010651 | 0.259333 | 0.073882 |
3 | 0.371874 | 0.258592 | 0.634631 |
4 | -0.22921 | 0.084731 | -0.39482 |
5 | 0.520023 | 0.553674 | 0.360524 |
can you please suggest how to do calculation for a set of cells in the table.
For example, calculate the average and std of row 2 and column 3 and 4, e.g. [2, 3:4].
Many thanks, is there any procedure would have such function?
Something like this:
data have;
set sashelp.class;
a=1;b=2;c=3;
run;
%let row=2;
%let col=2:5 ;
proc iml;
use have;
read all var _num_ into x;
close;
avg=mean(colvec(x[&row,&col]));
std=std(colvec(x[&row,&col]));
print avg,std;
quit;
Do you have SAS/IML?
Does this have to be done in a matrix, or can it be done in a SAS data step? Is it always columns 3 and 4 that is of interest, or can that change depending on various different circumstances?
Please don't say "I think I have...", please say either: you have it or you do not have it.
the column number is fixed always ID, x,x1-x7,
but the row number will change, due the updating database on daily basis.
Thanks.
@Jonison wrote:
the column number is fixed always ID, x,x1-x7,
but the row number will change, due the updating database on daily basis.
How does the programmer know which columns and rows to use for computing the mean?
would you please show me some example of using IML to do calculation? not familiar the syntax,
Thanks
Something like this:
data have;
set sashelp.class;
a=1;b=2;c=3;
run;
%let row=2;
%let col=2:5 ;
proc iml;
use have;
read all var _num_ into x;
close;
avg=mean(colvec(x[&row,&col]));
std=std(colvec(x[&row,&col]));
print avg,std;
quit;
Thanks for your kind help, it is really useful and works perfectly.
Do you have a "matrix" or a dataset? Assuming you have a dataset then you are asking for:
data want;
set have;
where id = 2 ;
avg = mean(of col3 col4);
std = std(of col3 col4);
run;
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.