BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hua
Obsidian | Level 7 hua
Obsidian | Level 7

Hello All,

 

I tried to find the first and last non-missing value in a dataset by group, but still have some trouble to do so. I hope someone in the SAS community groups can help. Thanks a lot!

I have a dataset looks like this:

stn year month day var
1 2000 12 29 0.5
1 2000 12 30 .
1 2000 12 31 0
1 2001 1 1 0.2
1 2001 1 2 1
1 2001 1 3 .
2 2000 12 29 .
2 2000 12 30 .
2 2000 12 31 .
2 2001 1 1 0
2 2001 1 2 1.5
2 2001 1 3 3

And I want to find the first and last non-missing observation(var) for each stn so that I could know the nonmissing var for each stn is from what time to when. What I means is, in this example, I want to find for stn 1 the first is in 12/29/2000 and the last is 1/2/2001. And for stn 2, the first is 01/01/2001, and the last is 01/03/2001.

 

If any one can assist in this problem I would greatly appreciate it!

 

Thank you and anxiously awaiting a reply!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

SAS has tools that make this easy:

 

data want;

set have;

by stn;

where var > .;

if first.stn or last.stn;

run;

 

The combination of WHERE + BY sets up the BY variables based on the observations that meet the WHERE condition.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

SAS has tools that make this easy:

 

data want;

set have;

by stn;

where var > .;

if first.stn or last.stn;

run;

 

The combination of WHERE + BY sets up the BY variables based on the observations that meet the WHERE condition.

hua
Obsidian | Level 7 hua
Obsidian | Level 7
It works! Thank you so much!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 6476 views
  • 1 like
  • 2 in conversation