BookmarkSubscribeRSS Feed
1239
Calcite | Level 5
Hi,

I want Average values of Mean or overall Mean value of dynamic variables. Variables may vary from project to project. Please some one help.

Thanks in Advance.


Data:
--------------------------------------------------
Project Country T1 T2
A INDIA 9 8
A US 7 6
A UK 5 4
---------------------------------------------------
Project Country T1 T2 T4
B INDIA 1 2 3
B US 5 4 7
B UK 6 8 9
---------------------------------------------------

Output Expected:
----------------------------------------------------------------------
Project Country T1 T2
A INDIA 9 8
A US 7 6
A UK 5 4
ALL_COUNTRY 7 6
----------------------------------------------------------------------

Project Country T1 T2 T4
B INDIA 1 2 3
B US 5 4 7
B UK 6 8 9
ALL_COUNTRY 4 4.67 6.33
----------------------------------------------------------------------
8 REPLIES 8
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello 1239,

Look at proc TABULATE or proc REPORT for this purpose. A combination of proc MEANS with a datastep could help too.
"I want Average values of Mean or overall Mean value of dynamic variables" it is not very clear. Does it mean that input and output dataset names and variable names have to be parameters to some macro program calculating the overall mean?

Sincerely,
SPR
1239
Calcite | Level 5
Hi SPR,

Actually dynamic variable means for some project variables will be T1, T2 and for some projects will be T1, T2, T4 so on...

T1, T2, T4 these are created from Macro. So this is not constant and it may vary depending on the projects.

Currently i need average mean value for T1, T2, T4 so on in the last row as show in the output expected.

Please help.
Cynthia_sas
SAS Super FREQ
Hi:
PROC MEANS supports the use of the automatic variable reference _NUMERIC_ -- which might do what you want. You can read about how the _TYPE_ variable is created and how you can use it to determine which variables contributed to the calculated statistics.

At some point, unless you generate the TABULATE or REPORT code with a macro program, you will have to use the variable names or report item names in the code, such as in a TABLE statement or in a DEFINE statement.

cynthia

[pre]

proc means data=sashelp.class mean;
class sex;
var _numeric_;
output out=work.mnout mean=;
run;

proc print data=work.mnout;
title '_type_ 0 is the overall mean; _type_ 1 is the class variable mean';
run;

proc means data=sashelp.class mean;
class name;
var _numeric_;
output out=work.namout mean= ;
run;

proc print data=work.namout;
title 'Using Name as the CLASS variable';
run;
[/pre]
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello 1239,

This is a solution:
[pre]
data i;
input Project $ Country $ T1 T2;
datalines;
A INDIA 9 8
A US 7 6
A UK 5 4
run;
data i1;
input Project $ Country $ K1 K2 K3;
datalines;
B INDIA 1 2 3
B US 5 4 7
B UK 6 8 9
run;
%macro a(in=,out=,prefix=);
proc means data=&in noprint;
output out=mean(drop=_:) mean=;
var &prefix:;
run;
data &out;
length Project $20;
set &in mean end=e;
Project=CATX(" ",Project,Country);
if e then Project="All_COUNTRY";
drop Country;
format &prefix: 5.1;
run;
%mend a;
%a(in=i,out=r,prefix=T)
%a(in=i1,out=r1,prefix=K)
[/pre]
Sincerely,
SPR
Ksharp
Super User
[pre]

data temp;
input Project $ Country $ T1 T2 ;
cards;
A INDIA 9 8
A US 7 6
A UK 5 4
;
run;
proc summary data=temp ;
var _numeric_;
output out=all_mean(drop=_type_ _freq_) mean= ;
run;
data want;
set temp end=last;
output;
if last then do;
set all_mean;
country='All_Country';
output;
end;
run;
[/pre]


Ksharp
1239
Calcite | Level 5
Hi Ksharp.

Thanks for your help. Its working fine but only thing is i need to format it.

Currently the output is coming as ALL_COUNTRY 7.766666667 7.166666667
so on.

I need output as ALL_COUNTRY 7.7 7.1

It should not round off but i need only one digit after decimal.

I tried adding format but no impact on output. Please help.

data temp;
input Project $ Country $ T1 T2 ;
cards;
A INDIA 9 8
A US 7 6
A UK 5 4
;
run;
proc summary data=temp ;
var _numeric_;
format _numeric_ 8.1;
output out=all_mean(drop=_type_ _freq_) mean= ;
run;
data want;
set temp end=last;
output;
if last then do;
set all_mean;
country='All_Country';
output;
end;
run;
Ksharp
Super User
OK.
It is easy.
[pre]


data temp;
input Project $ Country $ T1 T2 ;
cards;
A INDIA 9.5634 8.3234
A US 7.4334 6.5434
A UK 5.4343 4.5634
;
run;
proc summary data=temp ;
var _numeric_;
output out=all_mean(drop=_type_ _freq_) mean= ;
run;

proc format ;
picture myfmt
low-high='0009.9'
;
run;
data want;
set temp end=last;
format _numeric_ myfmt.;
output;
if last then do;
set all_mean;
country='All_Country';
output;
end;
run;
[/pre]


Ksharp
1239
Calcite | Level 5
Hi Ksharp,

Thanks a lot for your help. Its working as per my requirement.

Hi SPR and Cynthia@sas.Thanks for your help.

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!

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.

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
  • 8 replies
  • 1636 views
  • 0 likes
  • 4 in conversation