Dear All,
I have one data set. There are three scanners and each has two time points measurements with four different label results. I would like to get only the first time point results from these three scanners. But I can only get the first label results if I use the first option. Here is my code and data set I have and results I would like to have.
proc sort data=have; by Manufacturers study_date label ;run;
data want;
set have;
by Manufacturers study_date label;
if first.study_date;
run;
what I have:
Manufacturers | Study_Date | Label | mhpost | mhant | mhmid | mhup | mhlow |
N85148 | 8-Jan-13 | L1 | 67.25 | 65.88 | 61.50 | 82.05 | 82.81 |
N85148 | 8-Jan-13 | L2 | 68.48 | 72.60 | 62.50 | 84.14 | 88.10 |
N85148 | 8-Jan-13 | L3 | 69.83 | 80.63 | 67.58 | 84.59 | 87.05 |
N85148 | 8-Jan-13 | L4 | 67.60 | 79.55 | 70.60 | 89.19 | 93.35 |
N85148 | 19-May-13 | L1 | 67.34 | 65.46 | 61.58 | 82.39 | 83.10 |
N85148 | 19-May-13 | L2 | 68.04 | 72.94 | 63.80 | 85.36 | 87.90 |
N85148 | 19-May-13 | L3 | 69.00 | 76.90 | 66.82 | 86.65 | 88.14 |
N85148 | 19-May-13 | L4 | 67.50 | 79.44 | 72.12 | 88.96 | 92.19 |
N85257 | 1-Apr-13 | L1 | 67.25 | 66.25 | 61.80 | 81.19 | 82.42 |
N85257 | 1-Apr-13 | L2 | 70.45 | 74.35 | 65.30 | 84.00 | 85.05 |
N85257 | 1-Apr-13 | L3 | 70.50 | 78.80 | 66.20 | 86.85 | 89.84 |
N85257 | 1-Apr-13 | L4 | 66.25 | 78.90 | 73.30 | 88.09 | 92.12 |
N85257 | 6-Jun-13 | L1 | 66.80 | 66.32 | 61.44 | 82.37 | 82.78 |
N85257 | 6-Jun-13 | L2 | 68.16 | 74.08 | 63.20 | 84.30 | 86.04 |
N85257 | 6-Jun-13 | L3 | 68.78 | 77.94 | 65.84 | 86.81 | 88.15 |
N85257 | 6-Jun-13 | L4 | 66.86 | 78.60 | 72.02 | 88.62 | 92.43 |
N85286 | 21-Feb-13 | L1 | 67.78 | 67.00 | 63.35 | 81.55 | 81.90 |
N85286 | 21-Feb-13 | L2 | 68.83 | 73.15 | 64.58 | 84.70 | 85.91 |
N85286 | 21-Feb-13 | L3 | 69.55 | 78.08 | 66.73 | 85.19 | 86.96 |
N85286 | 21-Feb-13 | L4 | 67.70 | 80.35 | 70.80 | 88.23 | 92.32 |
N85286 | 20-Apr-13 | L1 | 66.52 | 66.10 | 61.58 | 81.19 | 82.04 |
N85286 | 20-Apr-13 | L2 | 67.26 | 72.10 | 62.46 | 84.77 | 86.14 |
N85286 | 20-Apr-13 | L3 | 69.46 | 76.96 | 65.78 | 84.74 | 87.23 |
N85286 | 20-Apr-13 | L4 | 67.82 | 78.72 | 71.80 | 87.42 | 90.34 |
what I want:
Manufacturers | Study_Date | Label | mhpost | mhant | mhmid | mhup | mhlow |
N85148 | 8-Jan-13 | L1 | 67.25 | 65.88 | 61.50 | 82.05 | 82.81 |
N85148 | 8-Jan-13 | L2 | 68.48 | 72.60 | 62.50 | 84.14 | 88.10 |
N85148 | 8-Jan-13 | L3 | 69.83 | 80.63 | 67.58 | 84.59 | 87.05 |
N85148 | 8-Jan-13 | L4 | 67.60 | 79.55 | 70.60 | 89.19 | 93.35 |
N85257 | 1-Apr-13 | L1 | 67.25 | 66.25 | 61.80 | 81.19 | 82.42 |
N85257 | 1-Apr-13 | L2 | 70.45 | 74.35 | 65.30 | 84.00 | 85.05 |
N85257 | 1-Apr-13 | L3 | 70.50 | 78.80 | 66.20 | 86.85 | 89.84 |
N85257 | 1-Apr-13 | L4 | 66.25 | 78.90 | 73.30 | 88.09 | 92.12 |
N85286 | 21-Feb-13 | L1 | 67.78 | 67.00 | 63.35 | 81.55 | 81.90 |
N85286 | 21-Feb-13 | L2 | 68.83 | 73.15 | 64.58 | 84.70 | 85.91 |
N85286 | 21-Feb-13 | L3 | 69.55 | 78.08 | 66.73 | 85.19 | 86.96 |
N85286 | 21-Feb-13 | L4 | 67.70 | 80.35 | 70.80 | 88.23 | 92.32 |
Thank you so much for your help in advance,
Bo
You have to sort by label before study_date :
proc sort data=have; by Manufacturers label study_date;run;
data want;
set have;
by Manufacturers label;
if first.label;
run;
PG
You have to sort by label before study_date :
proc sort data=have; by Manufacturers label study_date;run;
data want;
set have;
by Manufacturers label;
if first.label;
run;
PG
Thank you so much for your prompt help PGStats! It works! Bo
Or assuming at sorted by manufacturers
data want (drop= temp:);
set have;
by Manufacturers ;
length tempman $ 40;
retain tempman tempdate;
if first.Manufacturers then do;
tempman=Manufacturers;
tempdate=study_date;
end;
if tempman=Manufacturers and
tempdate=study_date;
run;
Thank you Ballardw for your suggestion! Bo
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.