Hi,
I have a lab dataset where I want to take the first observation for each category for each visit and subject. This is how it looks:
usubjid parameter visit
1001 chemistry screening
1001 chemistry screening
1001 chemistry screening
1001 chemistry screening
1001 Hematology screening
1001 Hematology screening
1001 Hematology screening
1001 urinalysis screening
1001 urinalysis screening
1001 urinalysis screening
1001 chemistry Day1
1001 chemistry Day1
1001 chemistry Day1
1001 hematology Day1
1001 hematology Day1
1001 urinalysis Day1
this is how data look like and have several subjects and another two visits. But the pattern is same.
The desired data is:
1001 chemistry screening
1001 hematology screening
1001 urinalysis screening
1001 chemistry day1
1001 hematology day1
1001 urinalysis day1.
Can someone please help with the code?
Thanks
Rashmi.
your question references columns not in your dataset.
@rashmirao99 wrote
I have a lab dataset where I want to take the first observation for each category for each visit and subject. This is how it looks:
is the category referencing the parameter and the subject referencing the usubjid?
So you want to do this for all the variables, correct? You basically want to remove duplicates?
proc sort data=lab out=want nodupkey;
by usubjid parameter visit;
run;
data have;
input (usubjid parameter visit) (:$12.);
cards;
1001 chemistry screening
1001 chemistry screening
1001 chemistry screening
1001 chemistry screening
1001 Hematology screening
1001 Hematology screening
1001 Hematology screening
1001 urinalysis screening
1001 urinalysis screening
1001 urinalysis screening
1001 chemistry Day1
1001 chemistry Day1
1001 chemistry Day1
1001 hematology Day1
1001 hematology Day1
1001 urinalysis Day1
;
data want;
set have;
by usubjid visit parameter notsorted;
if first.parameter;
run;
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.