Dear All:
My data set is as follows:
Time p ID
9:00:01 56.57 45
9:00:01 67.97 46
9:00:01 67.97 46
9:00:01 68.00 46
9:00:02 69.00 76
9:00:02 69.10 79
9:00:02 70.01 45
9:00:03 69.04 78
9:00:03 68.10 46
and so on
The output I want is the p observation. So in this example I need:
Time p ID
9:00:01 56.57 45
9:00:01 67.97 46
9:00:01 68.00 46
9:00:02 69.00 76
9:00:02 69.10 79
9:00:02 56.57 45
9:00:03 69.04 78
9:00:03 68.10 46
the code I wrote was
data want; set have;
by ID p time:
If first.p then output;
run;
Some thing does not seem to work with the code.
Thanks in advance.
R
Perhaps your values are not actually exactly the same?
data have;
input Time :time8. p ID;
format time time8.;
cards;
9:00:01 56.57 45
9:00:01 67.97 46
9:00:01 67.97 46
9:00:01 68.00 46
9:00:02 69.00 76
9:00:02 69.10 79
9:00:02 70.01 45
9:00:03 69.04 78
9:00:03 68.10 4
;
proc sort data=have out=_have;
by id p time;
run;
data want; set _have;
by ID p time;
If first.p then output;
run;
Your sample data appears to be sorted by TIME/P/ID. if that's true, then your idea of a data step with a BY statement and a"first." condition is correct, but needs tweaking, assuming what you want is to eliminate duplicate time/p/id combinations.
data want;
set have;
by time p id;
if first.id;
run;
Of course this means a given id or a given P can appears more than once for a given TIME. I presume that's ok.
Hello,
Are you trying to remove duplicate records, try the nodupkey option.
proc sort data=have out=want nodupkey;
by id p time;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.