Feel free to direct my to an article or post if this has been discussed previously.
I'd like to create a table that replicates an observation based on a frequency count. While I'm able to use the frequency (or weight) command for many functions, it would be nice to have a full cross-tabulation of the data as well. A sample of my data would be:
Have:
Group | Event | Study | Count |
1 | 1 | 1 | 3 |
1 | 0 | 1 | 2 |
0 | 1 | 1 | 4 |
Want:
Group | Event | Study |
1 | 1 | 1 |
1 | 1 | 1 |
1 | 1 | 1 |
1 | 0 | 1 |
1 | 0 | 1 |
0 | 1 | 1 |
0 | 1 | 1 |
0 | 1 | 1 |
0 | 1 | 1 |
I used low frequencies here but my frequencies are actually in the hundreds or thousands. My inkling is that I should be using an array within a data step but I haven't figured it out yet.
I appreciate any answers! I'm keen to learn different potential approaches as well.
data have;
input
Group Event Study Count;
cards;
1 1 1 3
1 0 1 2
0 1 1 4
;
run;
data want(drop=count i);
set have;
do i=1 to count;
output;
end;
run;
/* end of program */
data have;
input
Group Event Study Count;
cards;
1 1 1 3
1 0 1 2
0 1 1 4
;
run;
data want(drop=count i);
set have;
do i=1 to count;
output;
end;
run;
/* end of program */
Wow, I was way overthinking this. Thank you!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.