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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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