BookmarkSubscribeRSS Feed
lpy0521
Fluorite | Level 6

Hey there,

 

how can I make this happening in SAS? I have a columns called points and I would like to create sequential group id for consecutive null values

 

pointsgroup
1 
1 
.1
.1
1 
1 
.2
.2
1 
1 
.3
.3
.3

 

Thanks,

2 REPLIES 2
s_lassen
Meteorite | Level 14

Something like this?

data want;
  set have;
  if _N_=1 and missing(points) then _group=1;
  if missing(points) and not missing(lag(points)) then _group+1;
  if missing(points) then group=_group;
  drop _group;
run;
Ksharp
Super User
data have;
input points;
cards;
1
1
.
.
1
1
.
.
1
1
.
.
.
;

data want;
 set have;
 by points notsorted;
 if first.points and missing(points) then n+1;
 if missing(points) then group=n;
 drop n;
 run;

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!

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
  • 2 replies
  • 371 views
  • 3 likes
  • 3 in conversation