Need a code for SAS


#1

I have a dataset like Quater, Month , Sales given below:
1 Jan 300
1 Feb 450
1 Mar 220
2 Apr 76
2 May 722
2 Jun 151
3 Jul 112
3 Aug 90
3 Sep 800
4 Oct 1000
4 Nov 10
4 Dec 1222

How do I find the top 2 sales quate rwise ?
What would be the code in SAS for the same ?

Regards,
Sanket


#2

HI Sanket ,

please try
proc sort data = dataset_name ;
by quarter sales;
run;
It will sort sales within quarter.


#3

Hi Sanket,
You can try using first. and last. . You will get enough documentation around these flags. Essentially, what you will need to do is to set a counter which will reset with every chance in quarter. Create a flag which will have value as 1 if the counter is less than or equal to 2. Now once this flag is created, you can subset the entire dataset.
Hope this helps.
Tavish


#4

Thanks Dharamvir !!!


#5

Thanks Tavish !!! I will try reading documents of first and last flags and work for the same.