Help using Base SAS procedures

Create dataset from count data?

Reply
New Contributor
Posts: 2

Create dataset from count data?

Hi

I would like to convert a table that contains count data into a dataset that contains individual observations but I'm not sure how

For example, I would like to convert a table that looks like this

X Y count
1 3 2
2 6 4
5 4 3

into a dataset that looks like this

X Y
1 3
1 3
2 6
2 6
2 6
2 6
5 4
5 4
5 4

Does anyone know of a SAS code that can carry out this conversion?

Thanks!
Super Contributor
Super Contributor
Posts: 3,174

Re: Create dataset from count data?

DATA step with a KEEP and SET statement. And you would add a DO UNTIL (); / END; loop containing an OUTPUT statement. With the expression, you reference variable COUNT.

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search argument, this topic/post:

data step programming do loop output site:sas.com
N/A
Posts: 0

Re: Create dataset from count data?

Hello friend,

Try checking this code.
As Scott suggested the right method to do this.

data test;
input x y count;
cards;
1 3 2
2 6 4
5 4 3
;
run;

data new (drop= i count) ;
set test;
i=count;
do until (i=0);
output;
i=i-1;
end;
run;


Thanks,
Saurabh.
New Contributor
Posts: 2

Re: Create dataset from count data?

Thanks everyone -- these suggestions are helpful.
Ask a Question
Discussion stats
  • 3 replies
  • 136 views
  • 0 likes
  • 3 in conversation