BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
goodyucee
Calcite | Level 5

I have a dataset of >2000 hospitals that contains the two variables (columns)

1. HRR Code (numeric code for hospital referral region that the hospital belongs to). There are 306 distinct HRR codes

2. BDTOT (Number of beds in each hospital)

 

I want to compute a new column that will show the number of beds in all hospitals in a particular HRR. Is there a conditional expression (possibly with a wildcard) that I can use to sum all the hospital beds for each instance of the 306 HRRs?

 

Thanks for helping out.

 

1 ACCEPTED SOLUTION

Accepted Solutions
mklangley
Lapis Lazuli | Level 10

Here's how to do it using the Query Builder.

1. Locate your dataset. (Mine demo dataset is called MY_DATA, located in the WORK library).

mklangley_0-1595624481353.png

2. Double-click on the dataset and then select Query Builder

mklangley_1-1595624586594.png

3. Drag both columns (from the left) into the Select Data area in the middle.

mklangley_3-1595624662340.png

4. Click the dropdown for BDTOT under Summary, and click SUM.

mklangley_2-1595624634790.png

5. Click Run.

 

Using my data, here are the results I see:

mklangley_4-1595624794005.png

 

View solution in original post

4 REPLIES 4
mklangley
Lapis Lazuli | Level 10

If you're just looking for the sum of BDTOT for each HRR_Code, then this should do it:

proc sql;
    create table want as
    select  HRR_Code, sum(BDTOT) as total_beds_by_hrr format comma8.
    from have
    group by HRR_Code;
quit;

 

goodyucee
Calcite | Level 5

Thank you @mklangley. I am using Enterprise Guide here and I am a complete novice with programming.

Can you describe how I can compute the new column using the graphical interface of EG or the conditional expression that I have to type.

mklangley
Lapis Lazuli | Level 10

Here's how to do it using the Query Builder.

1. Locate your dataset. (Mine demo dataset is called MY_DATA, located in the WORK library).

mklangley_0-1595624481353.png

2. Double-click on the dataset and then select Query Builder

mklangley_1-1595624586594.png

3. Drag both columns (from the left) into the Select Data area in the middle.

mklangley_3-1595624662340.png

4. Click the dropdown for BDTOT under Summary, and click SUM.

mklangley_2-1595624634790.png

5. Click Run.

 

Using my data, here are the results I see:

mklangley_4-1595624794005.png

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2019 views
  • 0 likes
  • 2 in conversation