I am working with a large dataset that contains data for many hospitals (marked by "ahaid") across several years (2010-2015). Year is marked by "pryear." Each row indicates a unique surgical visit. I am trying to calculate the number of surgical visits per hospital for each year. My goal is to output a new dataset that contains "ahaid," "pryear," and count variables for each year (count_10, count_11, count_12...). I want the count variables to represent the total number of surgical visits for that value of ahaid for the specified year. I believe I can combine do loops and "by" statements to accomplish this, but am not sure of exactly the right sequence. Can anyone help?
Thank you very much!
Use PROC FREQ instead of do loops.
proc freq data=have;
tables ahaid*pryear;
run;
@jgreenberg321 wrote:
However I need to output the frequency values as new variables (one value per ahaid per pryear). Can I do that with the proc freq approach?
Yes. Use the PROC FREQ options named LIST and OUT=
proc freq data=have;
tables ahaid*pryear/list out=want noprint;
run;
Thank you! This seems to work well, though I expect the other solution proposed below would also work.
To organize my results by number of cases per year, I just used a transpose statement on the output dataset, though other solutions could have been as efficient or better. Thank you all for your help!
proc freq data=have;
table ahaid*pryear/list out=want_prelim (drop=percent) noprint;
run;
proc transpose data=want_prelim out=want_final (drop=_NAME_ _LABEL_);
by ahaid;
id pryear;
run;
Hello @jgreenberg321 ,
I was playing with your challenge and I have the following idea in attach
Regards,
CS
Thank you!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.