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!
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.
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.