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 data that looks like this:

 

builidingname    vax1  vax2    vax3     buildingtype

happy days           1        2          4        private

learning tree          2       1          3        public

bean stalk              1      1          2        public

 

How do I summarize the info for all buildings as well as by buildingtype so I get the data like this:

      vax1                             vax2                            vax3

all   public private          all   public private       all   public private 

4       3         1               4         2        2             9      5         4

 

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

@mkeintz sent me a private message. And I quote here.

 

 

You don't need data set WANT.  This is actually a good case to use multiple analysis vars in the proc tabulate:

 

proc tabulate data=have noseps order=freq;

  class buildingtype;

  var vax1-vax3;

  tables sum=''*(vax1 vax2 vax3)*(all buildingtype='')*f=9.0;

run;

 

 

Using the "order=freq" is a bit sneaky since it won't reliably order the table as (All,Public,Private) although it does in this case, as per OP's sample output.

View solution in original post

5 REPLIES 5
Reeza
Super User

Is this a report or a dataset that you need? I'm guesing report based on the structure.

 

Have you looked at proc report or tabulate? If so, what does your code look like so far?

I would probably recommend proc tabulate.

Ksharp
Super User
data have;
input buildingname & $20.   vax1  vax2    vax3     buildingtype $;
cards;
happy days           1        2          4        private
learning tree          2       1          3        public
bean stalk              1      1          2        public
;
run;
proc transpose data=have out=want;
by buildingname buildingtype notsorted;
var vax:;
run;
proc tabulate data=want;
 class _name_ buildingtype;
 var col1;
 table _name_=' '*(all buildingtype=' ')*col1=' '*sum=' '*f=best12.;
run;
Ksharp
Super User

@mkeintz sent me a private message. And I quote here.

 

 

You don't need data set WANT.  This is actually a good case to use multiple analysis vars in the proc tabulate:

 

proc tabulate data=have noseps order=freq;

  class buildingtype;

  var vax1-vax3;

  tables sum=''*(vax1 vax2 vax3)*(all buildingtype='')*f=9.0;

run;

 

 

Using the "order=freq" is a bit sneaky since it won't reliably order the table as (All,Public,Private) although it does in this case, as per OP's sample output.

jcis7
Pyrite | Level 9

Thank you!

Is it possible to output that into MS Excel instead of keeping it is SAS as HTML?

Ksharp
Super User

Sure.

 

ods excel file='c:\temp\x.xlsx';

proc tabulate............

..........

ods excel close;

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