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

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

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
  • 907 views
  • 0 likes
  • 3 in conversation