BookmarkSubscribeRSS Feed
Wouter
Obsidian | Level 7
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!!
2 REPLIES 2
Olivier
Pyrite | Level 9
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
Wouter
Obsidian | Level 7
Thanks! Works perfectly! Should have thought of myself...!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 907 views
  • 0 likes
  • 2 in conversation