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
;



data want;
set t;
by id;
if first.id and first.L > 1 then exp=. ;

run;

Hi,

in this sample I want to update exp to null in case that in every first ID the first L is >1 which is the case with ID = 3

Where is the mistake in the code?

 

Thanks for the help. 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

A first. variable is only created for variables named in the BY statement, and it is boolean, meaning it will only take on the values 0 or 1.

Corrected code:

data want;
set t;
by id;
if first.id and L > 1 then exp = .;
run;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

A first. variable is only created for variables named in the BY statement, and it is boolean, meaning it will only take on the values 0 or 1.

Corrected code:

data want;
set t;
by id;
if first.id and L > 1 then exp = .;
run;
cmemtsa
Quartz | Level 8
Thanks! That's correct.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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