BookmarkSubscribeRSS Feed
deleted_user
Not applicable
1) Why is SAS giving a warning? What's wrong? Thanks!
2) Can you explain the following lines? What does first.child mean or do?
if first.person then duplicate=0;
else duplicate=count(person, num, personum);

num is a character variable and has the following values: A01, A02, A03 ,etc
personum is a character variable and has the following values: 1,2,3,4,,5, etc

Thanks!

CODE:

data err;
set err;
person=num||personum;
keep num personum person;
run;

4567 data err;
4568 set err;
4569 by person;
4570 if first.person then duplicate=0;
4571 else duplicate=count(person, num, personum);
4572 run;

WARNING: In a call to the COUNT function or routine, the modifier "7" not valid
WARNING: In a call to the COUNT function or routine, the modifier "5 not valid.
WARNING: In a call to the COUNT function or routine, the modifier "7" not valid.
WARNING: In a call to the COUNT function or routine, the modifier "5" not valid.
WARNING: In a call to the COUNT function or routine, the modifier "7" not valid. corrected errors

Message was edited by: jcis
4 REPLIES 4
deleted_user
Not applicable
Part 1)

Well the syntax for COUNT is

COUNT(character-value,find-string<,'modifiers'>)

The only allowable modifiers are i,I,t,T

So your function call is sending the numbers 1-7 to the call , which is improper syntax.

Can't help you fix it unless you give us an idea of what it is supposed to do

Part 2)

first.child is a boolean
=1 if the current observation is the first one in the group formed by the BY variable (in this case child), and 0 otherwise.

Ike
deleted_user
Not applicable
Thanks Ike. I have a few questions:

What is an example of a character-value?
What is a string?
What is a modifier?
Can you explain the boolean idea more indepth?

Example of Data:

num personum
A01 1
A01 2
A01 3
A01 4
A02 1
A02 2
A02 3
A02 4
A03 1
A03 2
A03 3


I'm trying to find two of the same observations entered, or duplicates.
(EX: if there are two A01's with the same personum).
I undestand that the idea that two observations fields num and personum are combined. But how is a duplicate actually identified?

Thanks!
deleted_user
Not applicable
1) As to your queries about the syntax of COUNT function, refer to the following link:
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a002260230.htm

2) Boolean concept: When data is sorted on a particular variable (BY variable) in sas dataset, you can reference the first or last elements of the group by referencing them through first.variable and last.variable syntax.

For example let us take a part of ur dataset:

num personum
A01 1------------------ first.num
A01 2
A01 3
A01 4------------------ last.num
A02 1------------------ first.num
A02 2
A02 3
A02 4------------------ last.num

If you want to remove duplicates you can use PROC SORT with NODUPKEY.

But if you want to count duplicates you have to put your own logic. COUNT procedure does not do what you want, it will count the number of times that a specific substring of characters appears within a character string that you specify.

A sample logic that will do what you want might be:
I take that your dataset is already sorted BY num personum

data temp;
set err;
person=num||personum;
run;

proc sort; by person; run; (this might be redundant but still)

data temp;
set temp; by personum;
cnt=0;
if not first.personum then cnt = cnt + 1;
run;


The dataset temp will have a new variable "cnt" which will have the number of duplicate ocurrences of a particular combination num and personum.

A better way to do it might be:
data temp;
set err; by num personum;
cnt=0;
if first.num and not (first.personum) then cnt = cnt + 1;


Hope this helps.
deleted_user
Not applicable
Thanks for the link to the Call to Count function. And, thanks also fore the explanation of a Boolean. I'm looking into the SAS program a little more. Thanks!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1699 views
  • 0 likes
  • 1 in conversation