BookmarkSubscribeRSS Feed
rashmirao99
Fluorite | Level 6

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.

 

 

 

4 REPLIES 4
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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?

 

PeterClemmensen
Tourmaline | Level 20

So you want to do this for all the variables, correct? You basically want to remove duplicates?

Jagadishkatam
Amethyst | Level 16

 

 

proc sort data=lab out=want nodupkey;
by usubjid parameter visit;
run; 
Thanks,
Jag
novinosrin
Tourmaline | Level 20
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1633 views
  • 0 likes
  • 5 in conversation