BookmarkSubscribeRSS Feed
Brad39
Fluorite | Level 6

Please someone could help with below scenario to code through Proc SQL:

 

Scenario: we have a dataset with column : Paitent_Id, Name, Appointment_date and Amount_Paid.

I need to fetch report for top 10 Patient for each_month who paid the maximum Bill.

Below is the dummy data:

Patient_Id  Patient_Name  Appointment_date Bill_Paid

1                  A                      01/01/2000            250

2                  B                      21/02/2000            350

3                  C                     15/01/2000             400

4                  D                     17/02/2000             430

5                  E                      01/03/2000            500

 

 

 

Following is the code i've tried but i want to replicate same scenario through proc sql or if any other optimized solution someone could suggest, will be appreciated.

 

Code:

format date yymmn6.;

 

proc sort data=dummy out=sorted_op;

by date descending bill_paid;

run;

 

data final;

set sorted_op;

by date;

if first.date then n=1;

else n+1;

if n<=10;

run;

 

 

 

1 REPLY 1

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 896 views
  • 3 likes
  • 2 in conversation