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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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