turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- how can i count number of character value in proc ...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-11-2016 06:02 AM - edited 07-11-2016 06:44 AM

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

Accepted Solutions

Solution

07-11-2016
11:32 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-11-2016 09:09 AM

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;
```

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-11-2016 07:20 AM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-11-2016 07:26 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-11-2016 08:12 AM

Farm year nbr_bulls

A 2012 2739

A 2013 3799

A 2014 3678

A 2015 1968

B 2012 481

B 2013 1176

B 2014 1192

B 2015 1212

C 2012 193

C 2013 522

C 2014 454

C 2015 449

D 2012 404

D 2013 430

D 2014 426

D 2015 416

E 2012 822

E 2013 831

E 2014 856

E 2015 1008

Yes I want a count of distinct values.

thx

A 2012 2739

A 2013 3799

A 2014 3678

A 2015 1968

B 2012 481

B 2013 1176

B 2014 1192

B 2015 1212

C 2012 193

C 2013 522

C 2014 454

C 2015 449

D 2012 404

D 2013 430

D 2014 426

D 2015 416

E 2012 822

E 2013 831

E 2014 856

E 2015 1008

Yes I want a count of distinct values.

thx

Solution

07-11-2016
11:32 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-11-2016 09:09 AM

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;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-11-2016 11:32 AM

thx you verry much

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-11-2016 07:51 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-11-2016 08:12 AM

no I don't think so

thx

thx

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-11-2016 08:04 AM

You can also use proc tabulate if you want to customize your report, and as you've posted Proc SQL is an option.