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
points | group |
1 | |
1 | |
. | 1 |
. | 1 |
1 | |
1 | |
. | 2 |
. | 2 |
1 | |
1 | |
. | 3 |
. | 3 |
. | 3 |
Thanks,
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;
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;
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.