Solved
Contributor
Posts: 48

# Expanding Frequency tables into datasets

Good afternoon,

I am often given frequency tables which I would like to expand into data sets, which are more easy to manipulate. Is there a procedure that I could use?

For example, I would like to expand the frequency table below into the consequent data set.

GIVEN

 Age Group Laid off Retained up to 40 2 5 40-49 1 3

DESIRED OUTCOME

 Age Group Employment Up to 40 Laid Off Up to 40 Laid Off Up to 40 Retained Up to 40 Retained Up to 40 Retained Up to 40 Retained Up to 40 Retained 40-49 Laid Off 40-49 Retained 40-49 Retained 40-49 Retained

Accepted Solutions
Solution
‎12-02-2013 12:55 PM
Super User
Posts: 8,127

## Re: Expanding Frequency tables into datasets

data desired ;

set given ;

employment='Laid Off';

do _n_=1 to laid_off ;

output;

end;

employment='Retained';

do _n_=1 to retained ;

output;

end;

run;

Or you could created a smaller dataset with the a COUNT or FREQ variable.  Many procedures will allow you to tell it to use this variable as a weight or frequency.

data want ;

set given ;

employment='Laid Off';

count = laid_off ;

output;

employment='Retained';

count = retained ;

output;

run;

All Replies
Solution
‎12-02-2013 12:55 PM
Super User
Posts: 8,127

## Re: Expanding Frequency tables into datasets

data desired ;

set given ;

employment='Laid Off';

do _n_=1 to laid_off ;

output;

end;

employment='Retained';

do _n_=1 to retained ;

output;

end;

run;

Or you could created a smaller dataset with the a COUNT or FREQ variable.  Many procedures will allow you to tell it to use this variable as a weight or frequency.

data want ;

set given ;

employment='Laid Off';

count = laid_off ;

output;

employment='Retained';

count = retained ;

output;

run;

Contributor
Posts: 48

## Re: Expanding Frequency tables into datasets

Briliant!

Thank you!~

🔒 This topic is solved and locked.