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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

9 REPLIES 9
stat_sas
Ammonite | Level 13

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;

menhtp
Calcite | Level 5

STAT

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

stat_sas
Ammonite | Level 13

Hi,

What is the error message in log?

CTorres
Quartz | Level 8

Should be format     _name_    (two words)

zetter
Calcite | Level 5

This is what I get:

format_name_$variable.;

statement not valid or it is used out of proper order

LTWeiss
Calcite | Level 5

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;

stat_sas
Ammonite | Level 13

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;

menhtp
Calcite | Level 5

Still error being reported

714  Proc tabulate data =allresults2 out= resultta;

715  class _name_col1/preloadfmt;

ERROR: Variable _NAME_COL1 not found.

ballardw
Super User

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)

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 9 replies
  • 3961 views
  • 0 likes
  • 6 in conversation