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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1540 views
  • 0 likes
  • 2 in conversation