SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Change Frequency Table to Raw Data

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Change Frequency Table to Raw Data

I'm a new SAS user here. I have a SAS data set that is a frequency table, and I would like to create a new SAS data set that consists of the frequency table transformed to raw data. For example, the frequency table looks like:

 

score

count

0

1

1

3

2

4

 

And the outcome I want is:

 

score

0

1

1

1

2

2

2

2

 

That is, the raw data has one observation of 0, 3 observations of 1, and 4 observations of 2. Thank you in advance for any help!


Accepted Solutions
Solution
‎02-20-2018 10:24 AM
Super User
Posts: 6,632

Re: Change Frequency Table to Raw Data

Since this is not a standard feature, you need to do a little programming to make it happen.

 

First, create a SAS data set holding the counts from PROC FREQ:

 

proc freq data=have;

tables score / noprint out=temp_counts;

run;

 

Then take that SAS data set and write its contents to a text file:

 

data _null_;

set temp_counts;

file 'path to a raw data file to hold the results' noprint;

if _n_=1 then put 'score';

do k=1 to count;

   put score;

end;

run;

View solution in original post


All Replies
Solution
‎02-20-2018 10:24 AM
Super User
Posts: 6,632

Re: Change Frequency Table to Raw Data

Since this is not a standard feature, you need to do a little programming to make it happen.

 

First, create a SAS data set holding the counts from PROC FREQ:

 

proc freq data=have;

tables score / noprint out=temp_counts;

run;

 

Then take that SAS data set and write its contents to a text file:

 

data _null_;

set temp_counts;

file 'path to a raw data file to hold the results' noprint;

if _n_=1 then put 'score';

do k=1 to count;

   put score;

end;

run;

Occasional Contributor
Posts: 6

Re: Change Frequency Table to Raw Data

Posted in reply to Astounding

Thank you so much, very helpful!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 451 views
  • 0 likes
  • 2 in conversation