BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cmemtsa
Quartz | Level 8
data T;
input ID L EXP;
Datalines;
1 1 10
1 2 10
1 2 20
1 3 30
2 1 10
2 1 10
2 2 60
3 2 60
3 3 60
;

Hi,

I would to like to update Exp to 0 if for First.ID and L>1 for all instances of this ID (the sorting is done) i.e. the output should be

1 1 10
1 2 10
1 2 20
1 3 30
2 1 10
2 1 10
2 2 60
3 2 0
3 3 0
;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data T;
input ID L EXP;
Datalines;
1 1 10
1 2 10
1 2 20
1 3 30
2 1 10
2 1 10
2 2 60
3 2 60
3 3 60
;
data want;
 do until(last.id);
  set t;
  by id;
  if l<=1 then flag=1;
 end;

 do until(last.id);
  set t;
  by id;
  if not flag then exp=0;
  output;
 end;
 drop flag;
 run;

View solution in original post

2 REPLIES 2
Ksharp
Super User
data T;
input ID L EXP;
Datalines;
1 1 10
1 2 10
1 2 20
1 3 30
2 1 10
2 1 10
2 2 60
3 2 60
3 3 60
;
data want;
 do until(last.id);
  set t;
  by id;
  if l<=1 then flag=1;
 end;

 do until(last.id);
  set t;
  by id;
  if not flag then exp=0;
  output;
 end;
 drop flag;
 run;
cmemtsa
Quartz | Level 8

Thank you! It works.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 429 views
  • 1 like
  • 2 in conversation