Help using Base SAS procedures

Proc tabulate multiple variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Proc tabulate multiple variables

Got a data like this let us call it ball colour:

key        blue    red     yellow    grey

12         x              z       p           y

25         x              z        p

34         x                       p          y

87         x                                

I want to tabulate on a single table a count for each colour ( but names in shorthand) i.e B for blue etc

Colour  Number

B           4

R           2

Y           3

G           2          

thanks.


Accepted Solutions
Solution
‎10-17-2014 03:31 PM
Super User
Posts: 10,843

Re: Proc tabulate multiple variables

still not putting spaces between the variable names!.

class  _name_  col1; (two variables from the input data set)

is NOT the same as

class _name_col1; (one variable name _name_col1 NOT in the input data set)

View solution in original post


All Replies
Trusted Advisor
Posts: 1,219

Re: Proc tabulate multiple variables

proc format;
value $colour
'blue'='B'
'red'='R'
'yellow'='Y'
'grey'='G';
;

proc transpose data=have out=one;
var blue red yellow grey;
by key;
run;

proc tabulate data=one out=want;
class _name_ col1/preloadfmt;;
table _name_='Colour',n='Number';
format _name_ $colour.;
run;

Occasional Contributor
Posts: 13

Re: Proc tabulate multiple variables

STAT

Your format_name_ STATEMENT show s an error, can you rectify?

Trusted Advisor
Posts: 1,219

Re: Proc tabulate multiple variables

Hi,

What is the error message in log?

Regular Contributor
Posts: 180

Re: Proc tabulate multiple variables

Should be format     _name_    (two words)

Contributor
Posts: 36

Re: Proc tabulate multiple variables

This is what I get:

format_name_$variable.;

statement not valid or it is used out of proper order

Senior User
Posts: 1

Re: Proc tabulate multiple variables

The following will work also:

options nocenter;

data test;

infile cards missover;

input key (blue red yellow grey) (+1 $char1.);

cards;

12  x z p y

25  x z p 

34  x   p y

87  x                             

;

run;

ods html close;

ods html;

proc sql;

    select 'b' as Colour, sum(blue is not null) as Number from _last_

      outer union corr

  select 'r' as Colour, sum(red is not null) as Number from _last_

      outer union corr

  select 'y' as Colour, sum(yellow is not null) as Number from _last_

      outer union corr

  select 'g' as Colour, sum(grey is not null) as Number from _last_

  ;

quit;

Trusted Advisor
Posts: 1,219

Re: Proc tabulate multiple variables

There may be space issue when you are putting code into SAS. Instead use the following, just inserted spaces to make it work.

proc tabulate data=one out=want;

class  _name_  col1;

table  _name_ = 'Colour' , n='Number';

format   _name_   $colour.;

run;

Occasional Contributor
Posts: 13

Re: Proc tabulate multiple variables

Still error being reported

714  Proc tabulate data =allresults2 out= resultta;

715  class _name_col1/preloadfmt;

ERROR: Variable _NAME_COL1 not found.

Solution
‎10-17-2014 03:31 PM
Super User
Posts: 10,843

Re: Proc tabulate multiple variables

still not putting spaces between the variable names!.

class  _name_  col1; (two variables from the input data set)

is NOT the same as

class _name_col1; (one variable name _name_col1 NOT in the input data set)

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 481 views
  • 0 likes
  • 6 in conversation