Hi,
I have a dataset which looks like:
data have;
infile datalines;
input numbers;
datalines;
1
1
.
2
3
4
.
5
5
6
7
7
;
In case the previous obervation is not . and the present observation equals to the previous value, then i would like to set the current value to . So what I would like to have is
data want;
infile datalines;
input numbers;
datalines;
1
.
.
2
3
4
.
5
.
6
7
.
;
Can someone help me solve this problem? Many thanks in advance!
BR Dingdang
lag() or dif();
data have;
infile datalines;
input numbers;
datalines;
1
1
.
2
3
4
.
5
5
6
7
7
;
data want;
set have;
if dif(numbers)=0 then
numbers=.;
run;
lag() or dif();
data have;
infile datalines;
input numbers;
datalines;
1
1
.
2
3
4
.
5
5
6
7
7
;
data want;
set have;
if dif(numbers)=0 then
numbers=.;
run;
data have; infile datalines; input numbers; datalines; 1 1 . 2 3 4 . 5 5 6 7 7 ; run; data want; set have; by numbers notsorted; if not first.numbers then numbers=.; run; data want1; set have; by numbers notsorted; if numbers=lag(numbers) then numbers=.; run;
Xia Keshan
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.
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.