HI,
I want to count number of bulls by farm and by year.
my data is :
farm year bulls
A 2012 x
A 2013 y
A 2014 x
B 2015 k
B 2013 n
I used proc report :
proc report data=work.H nowd;
columns Farm year bulls;
define Farm/ group;
define year/ group;
define bulls / analysis n "Number of bulls";
run;
but it dosen't run because the var 'bulls' is not a numeric var.
thx
Distinct counts can be easily obtained with SQL. You could code a CREATE TABLE and use that table in PROC REPORT for presentation purposes.
data h;
input farm $ year bulls $;
cards;
A 2012 x
A 2012 p
A 2013 y
B 2013 x
B 2014 k
B 2015 n
;
proc sql;
select farm, year, count(distinct bulls) as nbr_bulls
from h
group by farm, year;
quit;
HI,
I think with proc sql is more easy :
proc sql;
create table nbr_F as
select Ferme, Annee_IA, count(num_national) as nbr_F
from Lait_plu.H
group by Ferme, Annee_IA;
quit;
Can you show what your expected output would look like. Much like proc report I also have no straigtforward idea of how to add / count that character variable " bulls". One thing I can imagine is that you would like a count of distinct values of bulls. But that would be guessing.
Regards, Jan.
Distinct counts can be easily obtained with SQL. You could code a CREATE TABLE and use that table in PROC REPORT for presentation purposes.
data h;
input farm $ year bulls $;
cards;
A 2012 x
A 2012 p
A 2013 y
B 2013 x
B 2014 k
B 2015 n
;
proc sql;
select farm, year, count(distinct bulls) as nbr_bulls
from h
group by farm, year;
quit;
Is converting 'bulls' to numeric in a DATA Step first an option for you?
SAS Sample for the INPUT and PUT functions. http://support.sas.com/kb/24/590.html
You can also use proc tabulate if you want to customize your report, and as you've posted Proc SQL is an option.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.