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

Hi,

 

I have the following code. 

proc sql;
select 'A' label='Variable',
 (select sum(A) from have) as All,
 (select sum(A) from have where SCHTYPE='PUBLIC') as Public,
 (select sum(A) from have where SCHTYPE='PRIVATE') as Private
from have(obs=1)
union 
select 'B' label='Variable',
 (select sum(B)from have) as All,
 (select sum(B)from have where SCHTYPE='PUBLIC') as Public,
 (select sum(B)from have where SCHTYPE='PRIVATE') as Private
from have(obs=1)
union
select 'C' label='Variable',
 (select sum(C) from have) as All,
 (select sum(C) from have where SCHTYPE='PUBLIC') as Public,
 (select sum(C) from have where SCHTYPE='PRIVATE') as Private
from have(obs=1)
union 
select 'D' label='Variable',
 (select sum(D)from have) as All,
 (select sum(D)from have where SCHTYPE='PUBLIC') as Public,
 (select sum(D)from have where SCHTYPE='PRIVATE') as Private
from have(obs=1)
union
select 'A/B' label='Variable',
 (select sum(A)/sum(B) from have) as All format=percent7.2, 
 (select sum(A)/sum(B)  from have where SCHTYPE='PUBLIC') as Public format=percent7.2,
 (select sum(A)/sum(B)  from have where SCHTYPE='PRIVATE') as Private format=percent7.2
from have(obs=1)
union 
select 'C/D' label='Variable',
  (select sum(C)/sum(D) from have) as All format=percent7.2,
 (select sum(C)/sum(D)  from have where SCHTYPE='PUBLIC') as Public format=percent7.2,
 (select sum(C)/sum(D)  from have where SCHTYPE='PRIVATE') as Private format=percent7.2
from have(obs=1)

;
quit;

I am getting the following output but need two things different:

 

 

1)Order of rows to be:

A

B

C

A/B

C/E

 

2) The values of A/B and C/E to be rounded to the nearest tenth of a percent. 

 

How do I do that?  Thanks!

 

Variable All Public Private
A 9398 2758 5281
A/B 25.19571 15.85057 31.43452
B 373 174 168
C 9771 2932 5449
C/D 7.52194 18.44025 8.662957
D 1299 159

629

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Since this doesn't have a common order, ie alphabetical or numerical, you'll have to manually order it. This means creating another variable that will have the order you want that's either alphabetical or numerical and you can then sort accordingly.

View solution in original post

2 REPLIES 2
Reeza
Super User

Since this doesn't have a common order, ie alphabetical or numerical, you'll have to manually order it. This means creating another variable that will have the order you want that's either alphabetical or numerical and you can then sort accordingly.

jcis7
Pyrite | Level 9
Thank you!

sas-innovate-2024.png

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.

 

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
  • 2 replies
  • 719 views
  • 0 likes
  • 2 in conversation