Hi there,
Has anyone know how to get a specific range of data?
For example, I have this dataset:
Station Year Month Day Temp Count
1 2000 1 1 3.2 .
1 2000 1 2 4.2 .
1 2000 1 3 3.5 1
1 2000 1 4 3.7 .
1 2000 1 5 2.1 .
1 2000 1 6 3.0 .
1 2000 1 7 2.2 2
1 2000 1 8 3.1 .
1 2000 1 9 2.3 .
1 2000 1 10 3.2 .
......
I want to keep only the observations from count=1 to count=2, and I have several years and several stations.
Thank you for help!
Best,
Hua
This should be workable:
data want;
do until (last.station);
set have;
by station;
if count=1 then found_1='Y';
if found_1='Y' and found_2 ne 'Y' then output;
if count=2 then found_2='Y';
end;
drop found_1 found_2;
run;
This should be workable:
data want;
do until (last.station);
set have;
by station;
if count=1 then found_1='Y';
if found_1='Y' and found_2 ne 'Y' then output;
if count=2 then found_2='Y';
end;
drop found_1 found_2;
run;
data have;
input Station Year Month Day Temp Count;
cards;
1 2000 1 1 3.2 .
1 2000 1 2 4.2 .
1 2000 1 3 3.5 1
1 2000 1 4 3.7 .
1 2000 1 5 2.1 .
1 2000 1 6 3.0 .
1 2000 1 7 2.2 2
1 2000 1 8 3.1 .
1 2000 1 9 2.3 .
1 2000 1 10 3.2 .
1 2001 1 1 3.2 1
1 2001 1 2 4.2 .
1 2001 1 3 3.5 1
1 2001 1 4 3.7 .
1 2001 1 5 2.1 .
1 2001 1 6 3.0 .
1 2001 1 7 2.2 2
1 2001 1 8 3.1 .
1 2001 1 9 2.3 .
1 2001 1 10 3.2 1
;
run;
data want;
do until(not missing(count) or last.Year);
set have;
by Station Year;
if first.Year then first=1;
end;
_count=count;
do until(not missing(count) or last.Year);
set have;
by Station Year;
if not first and not missing(_count) and missing(count)then output;
end;
drop _count first;
run;
Another way:
data want (drop=flag); set have; retain flag; if count=1 then flag=1; if count=2 then flag=.; if flag then output; run;
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!
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.