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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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