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.
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)
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;
STAT
Your format_name_ STATEMENT show s an error, can you rectify?
Hi,
What is the error message in log?
Should be format _name_ (two words)
This is what I get:
format_name_$variable.;
statement not valid or it is used out of proper order
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;
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;
Still error being reported
714 Proc tabulate data =allresults2 out= resultta;
715 class _name_col1/preloadfmt;
ERROR: Variable _NAME_COL1 not found.
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)
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.
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.