BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ari
Quartz | Level 8 ari
Quartz | Level 8

data:

 

 

IDab
1102
120014.4
14005
1600

5

want:

 

IDabc (flag)
11020
120014.40
140050
160051

 

So,  variable b has same value 5 in rows 3 and 4. I need to flag first value (row 3)as 0 and subseqent rows containing value 5 as 1.

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
jklaverstijn
Rhodochrosite | Level 12

How about this then:

proc sort data=have;
   by id b;
run;
data want;
   set have;
   by id b;
   c = 0;
   if not first.b and b=5 then c=1;
run;

- Jan

 

 

View solution in original post

5 REPLIES 5
jklaverstijn
Rhodochrosite | Level 12

This is my 2 cents. Depending on what you'd like to do with variable a your final version can differ. But the use of first. will be my recommendation.

proc sort data=have;
   by id b;
run;
data want;
   set have;
   by id b;
   if first.b then c=0;
   else c=1;
run;

Regards,

- Jan.

 

ari
Quartz | Level 8 ari
Quartz | Level 8

You code works but I need to flag only  one numeric value 5.  For instance, if there are duplicate 8 values , there is no need to flag

jklaverstijn
Rhodochrosite | Level 12

How about this then:

proc sort data=have;
   by id b;
run;
data want;
   set have;
   by id b;
   c = 0;
   if not first.b and b=5 then c=1;
run;

- Jan

 

 

ari
Quartz | Level 8 ari
Quartz | Level 8

Thanks. It works Smiley Happy

jklaverstijn
Rhodochrosite | Level 12

Good to hear. Glad to be of help. Please do not hesitate to flag the question as resolved.

 

Regards Jan.

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
  • 5 replies
  • 1051 views
  • 1 like
  • 2 in conversation