BookmarkSubscribeRSS Feed
SAS_inquisitive
Lapis Lazuli | Level 10

 Hello,

 

Are below two DATA step (test1, test2) same ? I am assuming the NOT FIRST.ID  is implied in test2.

 


data test;
input id x;
cards;
1 2
1 2
2 3
2 2
;
run;

data test1;
set test;
by id;
retain val;
if first.id then val = 1;
else if not first.id and x > 1 then val = 5;
run;

data test2;
set test;
by id;
retain val;
if first.id then val = 1;
else if x > 1 then val = 5;
run;
1 REPLY 1
Reeza
Super User

Yes, because the only way to enter the second condition is if it's not first.ID. 

 

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 909 views
  • 1 like
  • 2 in conversation