Help using Base SAS procedures

proc rank,group and sort data

Reply
Occasional Contributor
Posts: 11

proc rank,group and sort data

 Hi, 

 

I am trying to group the data into 10 groups based upon the ranking. While I initially rank the data  & grouping them it is working fine & I am able to 10 ranks in the output 

 

the code that I used is: 

 

proc rank data=mylib.result groups=10 out=mylib.frank ties=mean;
var P_1;
ranks ranks;
run;

 

But when I am sorting the data into groups then I surprisingly see that the entire data is grouped into 3 groups(7,8,9)  and the sorting happens into only as 3 groups. I am not getting where I am doing a mistake 

 

The code that I am using for sorting the data is 

 

proc sort data=mylib.frank out=mylib.logsor;
by descending ranks;
run;

 

please help

Super User
Posts: 10,497

Re: proc rank,group and sort data

You would have to provide example data that has the behavior you describe. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

If the variable only has 3 values you won't get 10 ranks.

Note that asking for 10 groups should have 0 to 9 as the values of the ranks.

Occasional Contributor
Posts: 11

Re: proc rank,group and sort data

Please find the data in the attachment. It clearly has 10 values in the selection. However, try to sort the same data it will show you only 3 ranks post sorting.

Super User
Posts: 10,497

Re: proc rank,group and sort data

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Occasional Contributor
Posts: 11

Re: proc rank,group and sort data

Hi, 

 

I have provided the sas output in the attachment.Can you help me out!

Attachment
Super User
Posts: 10,497

Re: proc rank,group and sort data

Note that SAS data sets are dependent on operating system and also "bitness" 32 or 64 bit of the operating system. If your data is made on Linux or AIX it is not necessarily readable from Windows, or vice versa. That is why I mention the DATA STEP CODE generator. Then everyone can use the result.

 

Also, did you have any operations run on your Frank data set between the creation in Proc Rank and the proc sort step?

If you did something like:

 

data frank;

    set frank;

    if <some condition>;

run;

then you likely removed some of the values you are concerned with.

Trusted Advisor
Posts: 1,372

Re: proc rank,group and sort data

It is my first time to use proc rank, so I have done some technical research with hope it may help:

 

1) The FRANK.xlsx , sheet FRANK, has 375 observations and 22 variables.

2) Sorting NODUPKEY by P_1 results out in 18 unique values.

3) Sorting NODUPKEY by RANKS results out in 9 unique values. (value 5 is absent);

4) running code as given (adapted to my SAS UE environment): 

  

proc rank data=TEST groups=10 out=RANKS ties=mean;
var P_1;
ranks;   /* ranks;  */
run;

   result into 4 groups 0,1,2,3 ; 

Occasional Contributor
Posts: 11

Re: proc rank,group and sort data

@Shmuel.You mean to say that there are obly 4 variants of data in my dataset....if this is the how to sort my data without loosing the grouping..
Trusted Advisor
Posts: 1,372

Re: proc rank,group and sort data

NO, I'm not analyst and I dont understand what is going behind the proc rank. I just wanted to give baldraw information as he is not downloading xlsx file. As I said - just technical research.
Trusted Advisor
Posts: 1,372

Re: proc rank,group and sort data

BTW, continuing my research on proc rank - 

when I added an ID=_N_ to the TEST input dataset,

I did get 9 grops with ranks equal to the original ranks value.

 

I have no idea or explanation why proc rank changed results.

Ask a Question
Discussion stats
  • 9 replies
  • 176 views
  • 0 likes
  • 3 in conversation