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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 596 views
  • 3 likes
  • 2 in conversation