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

Hi , i have following detailed output dataset 

.

QuantityPharmacyBrand_namecostStrength
15OTHERDrug2$391.6330 MG
15OTHERDrug2$382.3830 MG
8PHARMACY2Drug2$213.3230 MG
30OTHERDrug2$1,553.8060 MG
44PHARMACY3Drug2$3,450.5490 MG
44PHARMACY3Drug2$3,450.5490 MG
44PHARMACY3Drug2$3,450.5490 MG
31OTHERDrug2$824.2530 MG
31OTHERDrug2$802.8530 MG
31OTHERDrug2$802.8530 MG
15PHARMACY1Drug2$400.4430 MG
30OTHERDrug2$764.7530 MG
30OTHERDrug2$779.2730 MG
23OTHERDrug2$586.3130 MG
30OTHERDrug2$782.4730 MG
30OTHERDrug2$782.4730 MG
30OTHERDrug2$782.4730 MG
30OTHERDrug2$800.4930 MG
4OTHERDrug2$101.9730 MG
30PHARMACY1Drug2$800.4930 MG
30OTHERDrug2$776.1830 MG
30OTHERDrug2$779.8630 MG
60OTHERDrug2$3,127.5560 MG
30OTHERDrug2$764.7530 MG
15OTHERDrug2$382.3830 MG
30OTHERDrug2$776.9530 MG
60OTHERDrug2$1,140.9330 MG
30PHARMACY1Drug2$800.4930 MG
60PHARMACY1Drug2$3,200.7460 MG
12PHARMACY2Drug2$319.4930 MG
30OTHERDrug2$1,529.5060 MG
16OTHERDrug2$420.0830 MG
30OTHERDrug2$764.7530 MG
30PHARMACY2Drug2$797.2130 MG
7OTHERDrug2$205.2330 MG
7OTHERDrug2$205.2330 MG
7OTHERDrug2$205.2330 MG
13OTHERDrug2$331.3930 MG
4OTHERDrug2$107.1630 MG
15PHARMACY1Drug2$400.4430 MG
15PHARMACY1Drug2$400.4430 MG
13OTHERDrug2$307.8530 MG
30OTHERDrug2$1,529.5060 MG
30PHARMACY1Drug2$800.4930 MG
30PHARMACY1Drug2$800.4930 MG
30PHARMACY1Drug2$800.4930 MG
30OTHERDrug2$782.4730 MG
30OTHERDrug2$1,553.8060 MG
30OTHERDrug2$1,553.8060 MG
15OTHERDrug2$1,127.0190 MG
15OTHERDrug2$1,127.0190 MG
30OTHERDrug2$779.8630 MG
30OTHERDrug2$1,545.9660 MG
15OTHERDrug2$400.4430 MG
30PHARMACY1Drug2$1,600.5760 MG
30PHARMACY1Drug2$1,600.5760 MG
45OTHERDrug2$1,147.1330 MG
30OTHERDrug2$785.0530 MG
30PHARMACY1Drug2$800.4930 MG
30OTHERDrug2$782.4730 MG
30OTHERDrug2$785.0530 MG
30PHARMACY1Drug2$1,600.5760 MG
8OTHERDrug2$212.7130 MG
8OTHERDrug2$212.7130 MG
15OTHERDrug2$391.6330 MG
30OTHERDrug2$764.7530 MG
20OTHERDrug2$518.0030 MG
20OTHERDrug2$518.0030 MG

i wanted to summary dataset as something similar below

 

YearBrandStrengthPharmacy NameTotal CostAvg. Units Dispensed
2019Drug2  $48,377.8529
2019Drug230 MG $16,905.3524
 Drug230 MGOther$12,292.4226
 Drug230 MGPharmacy1$3,602.4027
 Drug230 MGPharmacy2$1,010.5319
2019Drug260 MG $18,866.8636
 Drug260 MGOther$10,864.4135
 Drug260 MGPharmacy1$8,002.4538
2019Drug290 MG $12,605.6430
 Drug290 MGPharmacy3$10,351.6244
 Drug290 MGOther$2,254.0215

 

can you please help

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

This is exactly what PROC SUMMARY does

 

Example code:

 

proc summary data=have;
    class year brand strength pharmacy;
    types year year*brand year*brand*strength year*brand*strength*pharmacy;
    var cost quantity;
    output out=want mean(quantity)=avg_units_dispensed
        sum(cost)=total_cost;
run;

PROC REPORT will do similar things in this situation.

--
Paige Miller

View solution in original post

3 REPLIES 3
Reeza
Super User
PROC TABULATE will do what you want.
PaigeMiller
Diamond | Level 26

This is exactly what PROC SUMMARY does

 

Example code:

 

proc summary data=have;
    class year brand strength pharmacy;
    types year year*brand year*brand*strength year*brand*strength*pharmacy;
    var cost quantity;
    output out=want mean(quantity)=avg_units_dispensed
        sum(cost)=total_cost;
run;

PROC REPORT will do similar things in this situation.

--
Paige Miller
Patrick
Opal | Level 21

@sas33 

Please post the same questions only once so that the whole discussion stays together in a single place.

More here: https://communities.sas.com/t5/SAS-Programming/Averages-summary-level/m-p/535965#M147227 

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 634 views
  • 0 likes
  • 4 in conversation