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!
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;
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;
Thank you so much, very helpful!
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.
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.