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...!

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!

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.

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