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;
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 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.