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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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;

View solution in original post

2 REPLIES 2
Haikuo
Onyx | Level 15

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;

Ksharp
Super User
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 814 views
  • 4 likes
  • 3 in conversation