BookmarkSubscribeRSS Feed
LineMoon
Lapis Lazuli | Level 10

Hello,

I want to write this

 

proc sql;

  create table test as

  select  t1.*, t2.v

  from  t1 left join t2

  on t1.w=t2.w;

quit;

 

Is there any mather , if I do not use " order by ...", an other mean, sas can give any false result ?

if we do not write

proc sql;

  create table test as

  select  t1.*, t2.v

  from  t1 left join t2

  on t1.w=t2.w

  order by m1,

quit;

 

If yes, please can you give some exemples ?

 

 

 

5 REPLIES 5
hbi
Quartz | Level 8 hbi
Quartz | Level 8

The presence or lack of an "order by" statement in SQL will not affect the number of observations in the output dataset.

 

The above statement would be true, in a join even if you "ORDER BY" a variable that is not in the output dataset.

 

Even if you added something weird, like " ORDER BY monotonic(), ranuni(123) ", it should not affect the number of observations in the output dataset. 

ballardw
Super User

I am not sure that I understand what you mean by "false result";

 

Currently the implementation of proc sql without an order by variable will tend to order data by the values of the varaibles as they appear on the Select clause. The order of set T1 in your example may not be the order it had going in.

LineMoon
Lapis Lazuli | Level 10

you say "Currently the implementation of proc sql without an order by variable will tend to order data by the values of the varaibles as they appear on the Select clause"

 

You mean that : sas will order the final data by the variables in select clause ?

Thank you

art297
Opal | Level 21

Your code works as is! The only problem might be if v and m1 are in both datasets. However, the result of either run wouldn't be false in such cases, just not what you might have expected.

 

 

PGStats
Opal | Level 21

It might only be a transcription typo but the comma after m1 should be a semicolon. Otherwise, proc SQL will be looking for a variable named quit.

PG

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 3249 views
  • 0 likes
  • 5 in conversation