跨组汇总SAS中的数据

跨组汇总SAS中的数据,sas,Sas,我的数据集的格式如下所述: NEWID Age H_PERS Income OCCU FAMTYPE REGION Metro(Yes/No) Exp_alcohol population sample-(This is the weighted population each new id represents) etc. 我想生成一个总结视图,如下所示: average expenditure value (This should be sum of (exp_alcohol/popula

我的数据集的格式如下所述:

NEWID
Age
H_PERS
Income
OCCU
FAMTYPE
REGION
Metro(Yes/No)
Exp_alcohol
population sample-(This is the weighted population each new id represents) etc.
我想生成一个总结视图,如下所示:

average expenditure value (This should be sum of (exp_alcohol/population sample))

% of population sample across Region Metro and each demographic variable 

请帮助我了解您的想法。

因为我看不到您的数据集,而且您的描述也不太清楚,我猜您的数据看起来像这样,您希望添加一些新的变量来总结您的数据

data alcohol;
input NEWID Age H_PERS Income OCCU $ FAMTYPE $ REGION $ Metro $ 
Exp_alcohol population_sample;
datalines;
1234 32 4 65000 abc m CA Yes 2 4
5678 23 5 35000 xyz s WA Yes 3 6
9923 34 3 49000 def d OR No 3 9
8844 26 4 54000 gdp m CA No 1 5
;
run;

data summar;
    set alcohol;
    retain TotalAvg_expend metro_count total_pop;

    Divide = exp_alcohol/population_sample;
    TotalAvg_expend + Divide; 
    total_pop + population_sample;
    if metro = 'Yes' then metro_count + population_sample;
    percent_metro = (metro_count/total_pop)*100;
    drop NEWID Age H_PERS Income OCCU FAMTYPE REGION Divide;
run;
输出:

                  Exp_     population_    TotalAvg_    metro_    total_    percent_
       Metro    alcohol       sample        expend      count      pop       metro

        Yes        2            4          0.50000        4         4       100.000
        Yes        3            6          1.00000       10        10       100.000
        No         3            9          1.33333       10        19        52.632
        No         1            5          1.53333       10        24        41.667

人口统计变量
的信息有点不清楚。你已经提供了。我们能看一下示例数据集或预期输出吗?询问代码的问题必须表明对问题的最低理解。