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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.