SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

data manipulation

Reply
Occasional Contributor
Posts: 8

data manipulation

Hi everybody,

 

I have a question about data management. 

 

According to the labdate, extract the earliest 2 labs named as “b”  after testdate for each ID.

 

Thank you so much, 

 

Here is the dataset

 

id

lab

testdate

labdate

1

a

1/1/2015

1/2/2015

1

a

1/1/2015

1/3/2015

1

b

1/1/2015

12/1/2014

1

b

1/1/2015

1/2/2015

1

b

1/1/2015

1/3/2015

1

b

1/1/2015

1/4/2015

2

a

2/1/2015

1/2/2015

2

a

2/1/2015

2/1/2015

2

b

2/1/2015

2/1/2015

2

b

2/1/2015

2/2/2015

2

b

2/1/2015

2/3/2015

2

b

2/1/2015

2/4/2015

3

a

3/1/2015

2/1/2015

3

a

3/1/2015

3/1/2015

3

b

3/1/2015

4/1/2015

3

b

3/1/2015

3/2/2015

4

b

4/1/2015

1/1/2015

4

a

4/1/2015

4/1/2015

4

a

4/1/2015

5/1/2015

4

b

4/1/2015

5/2/2015

4

b

4/1/2015

5/3/2015

Respected Advisor
Posts: 4,173

Re: data manipulation

This looks like a study question to me. If so then you should first spend some of your own time with it and only post a question if you get stuck.

If you get stuck: Please post the code you've got already and explain what's not working. 

 

It would also help if you could post data as a SAS data step creating a SAS table.

Occasional Contributor
Posts: 8

Re: data manipulation

thank you. I will learn to ask question more professionally.

Respected Advisor
Posts: 4,927

Re: data manipulation

Is this a homework? In any case, experiment with the following to understand why it works.

 


proc sort data=have; by id lab labdate; run;

data want;
set have; by id;
where lab="b" and labdate>testdate;
if first.id then order = 0;
order + 1;
if order < 3 then output;
drop order;
run;

proc print data=want noobs; run;
PG
Occasional Contributor
Posts: 8

Re: data manipulation

Thank you for the response especially for the part of obtaining the first and second earliest dates.

 

 

Ask a Question
Discussion stats
  • 4 replies
  • 334 views
  • 2 likes
  • 3 in conversation