BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ccasagran737
Fluorite | Level 6

Hy,

I'm running this program:

proc sql;
	select  "TOTAL" as dest,
			sum(Boarded) as Boarded format comma.
 	from sasuser.LAGUARDIA
 		outer union  
		 	select Dest,
		 		   sum(Boarded) as Boarded format comma.
		 	from sasuser.LAGUARDIA
		 	group by Dest;
quit;

and SAS shows me this result:

Capture3.PNG

I'd like to see the result of the first query (total boarded) just under the result of the second query (total boarded group by destination) without missing data. Something like this:

Capture3bis.png

Is it possible? If yes, could you help me...thank a lot!

Have a nice day,

Daniele

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Drop the OUTER and let UNION work as intended.

If you want to impose an order than spell it out.

proc sql;
  select  "TOTAL" as sex 
       , sum(weight) as weight format comma.
       ,  1 as ordervar
  from sashelp.class
union
  select sex
       , sum(weight) as weight format comma.
       , 2 as ordervar
  from sashelp.class
  group by sex
  order by ordervar, sex
  ;
quit;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

hi @Ccasagran737 

 

Try using UNION instead of OUTER UNION

novinosrin
Tourmaline | Level 20

Well, with the above being said, if you still want to force OUTER UNION to overlay columns corresponding to the first select query, then

try OUTER UNION Corr

 

But please restrain such practices in a production code.

Reeza
Super User
Do you have to use PROC SQL? Tabulate wold be more appropriate here.
Reeza
Super User
proc tabulate data=sashelp.baseball;
class Team ;
var salary;
table (all = 'Total' team =''), Salary*Sum*f=dollar20. ;
run;
Tom
Super User Tom
Super User

Drop the OUTER and let UNION work as intended.

If you want to impose an order than spell it out.

proc sql;
  select  "TOTAL" as sex 
       , sum(weight) as weight format comma.
       ,  1 as ordervar
  from sashelp.class
union
  select sex
       , sum(weight) as weight format comma.
       , 2 as ordervar
  from sashelp.class
  group by sex
  order by ordervar, sex
  ;
quit;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1494 views
  • 0 likes
  • 4 in conversation