Hello, first time user for a couple of weeks now and have an issue with the SORT function.
When I sort by var (which is numeric, 1 until 13) I get:
1
10
11
12
13
2
3
4
5
6
etc.
In my other similar database I didn't have this issue, strange. Anyone knows how to fix this? Here's the basic code:
Proc sort data = data out = sorteddata;
by variable;
RUN;
Thanks.
It doesn't look like a numeric I am afraid. It looks like that variable is a character, hence it Is sorting textually.
It doesn't look like a numeric I am afraid. It looks like that variable is a character, hence it Is sorting textually.
I just ran a PROC CONTENTS and you're right. I find it strange it switched to Char, since it was Num in my main database, but thanks!
There is an option in proc sort can do that ,you need to check documentation . another way is sql.
Here is :
NUMERIC_COLLATION=on
Message was edited by: xia keshan
Where do I put this in my code? Just out of curiosity. I just changed my variable to numeric by multiplying it by 1 now. Thanks.
data test; length v $ 3; input v; cards; 1 10 11 12 13 2 3 4 5 6 ; run; proc sort data=test sortseq=linguistic(numeric_collation=on); by v; run; proc print data=test; run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.