質問

I need to find an easy way to convert a SAS data set to a frequency data set.

data have;
input desc $ x1 x2 x3 x4;
cards;
w 30 40 20 30
y 50 30 20 0
z 20 20 10 0
;
run;

I want to end up with a SAS data set that looks like this:

desc  x1  x2  x3  x4
w    .25 .33 .17 .25
y    .50 .30 .20  0
z    .40 .40 .20  0

A caveat: --This is used in a program in which the number of variables/observations changes, so must be able to handle that. In other words, sometimes the data may have observations w,y,z and also f, q, d. Furthermore, there may also be any number of x variables (say x5, x6, x7, etc).

Any help would be appreciated. I have tried exporting from proc freq or proc tabulate. Can't quite get it to work.

Thanks.

役に立ちましたか?

解決

It can be done with array easily:

data want;
    set have;
    array temp _NUMERIC_;
    sum=sum(of temp[*]);
    do over temp;
         temp=temp/sum;
    end;
    drop sum;
run;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top