how to count id number

Reply
Occasional Contributor
Posts: 15

how to count id number

I have data like this

data have;

infile datalines;

input policynumber$8.;

datalines;

m2227eqw,wy3747387,hsdahah

schaxnbbxc

847e7w87

47ew7837

ds6778989

fg848484,rt222222,y72378w

;

run;

how to find out count policy number ?

actual count is 10 but it count came 6.;

thanks in advanc

Respected Advisor
Posts: 4,736

Re: how to count id number

Posted in reply to padmakumariMiriyala

That's not about the count but about your input statement which only reads the first field per line (and you have 6 lines).

Valued Guide
Posts: 864

Re: how to count id number

Posted in reply to padmakumariMiriyala

Two things to point out.  You your length assignments are incorrect and you are only loading one column when you have three.

Hope this helps:

data have;

infile datalines dsd;

length policynumber1 policynumber2 policynumber3 $10.;

input policynumber1$ policynumber2$ policynumber3$;

datalines;

m2227eqw,wy3747387,hsdahah

schaxnbbxc,,

847e7w87,,

47ew7837,,

ds6778989,,

fg848484,rt222222,y72378w

;

run;

proc sql;

create table want as

select sum(count(policynumber1),count(policynumber2),count(policynumber3)) as count

from have;

Super User
Posts: 6,781

Re: how to count id number

Posted in reply to padmakumariMiriyala

Here's an alternative that uses your original version of the data:

data have;

infile datalines dsd;

length policynumber $ 10;

input policynumber @@;

datalines;

m2227eqw,wy3747387,hsdahah

schaxnbbxc

847e7w87

47ew7837

ds6778989

fg848484,rt222222,y72378w

;

This code doesn't count the policy numbers, because your original code didn't count them.  But it does give you each policy number as a separate observation.

Good luck.

Ask a Question
Discussion stats
  • 3 replies
  • 276 views
  • 1 like
  • 4 in conversation