Help using Base SAS procedures

Checking for multiple numbers

Reply
Contributor
Posts: 62

Checking for multiple numbers

Hi all!

Should be a simple task, but I don't get the code right...

I want to know (and FLAG) if a record contains a 1 time number or if there are other records with the same number. So I've got a dataset like:

1 text
2 text
2 text
3 text
4 text
4 text
4 text

I want to create a 'FLAG', so I know a number appears more than once in the dataset. The outcome should be something like:

1 text 0
2 text 1
2 text 1
3 text 0
4 text 1
4 text 1
4 text 1

Can anyone help me with this? Thanks!!
Super Contributor
Posts: 260

Re: Checking for multiple numbers

Hi Wouter.
If your dataset is already sorted, what you can do is :
[pre]
DATA myData ;
SET myData ;
BY myVariable ;
IF NOT (FIRST.myVariable AND LAST.myVariable) THEN flag = 1 ;
ELSE flag = 0 ;
RUN ;
[/pre]
Regards
Olivier
Contributor
Posts: 62

Re: Checking for multiple numbers

Thanks! Works perfectly! Should have thought of myself...!
Ask a Question
Discussion stats
  • 2 replies
  • 127 views
  • 0 likes
  • 2 in conversation