BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
akosh
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

2 REPLIES 2
Astounding
PROC Star

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;

akosh
Calcite | Level 5

Thank you so much, very helpful!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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