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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 771 views
  • 0 likes
  • 4 in conversation