BookmarkSubscribeRSS Feed
sree0203
Calcite | Level 5

 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

9 REPLIES 9
ballardw
Super User

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.

sree0203
Calcite | Level 5

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.

ballardw
Super User

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.

sree0203
Calcite | Level 5

Hi, 

 

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

ballardw
Super User

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.

Shmuel
Garnet | Level 18

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 ; 

sree0203
Calcite | Level 5
@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..
Shmuel
Garnet | Level 18
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.
Shmuel
Garnet | Level 18

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 2435 views
  • 0 likes
  • 3 in conversation