turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Descriptive Statistics for Longitudinal (long) Dat...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-15-2017 10:03 PM

Hi everyone,

I have a data set in long format (varied number of observations per subject) with 5 outcome variables. However, not all outcome variables are measures in each observations. I want to get means for each outcome variable the first time it is observed.

Therefore, using first.id does not work (the first observation per subject doesn't necessarily have the first measure of that outcome).

Any ideas?

doing

IF first.id AND first.outcome then output

does not work either.

Accepted Solutions

Solution

11-16-2017
12:34 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LGrau

11-16-2017 11:00 AM

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LGrau

11-15-2017 10:05 PM

Hi everyone,

I have a data set in long format (varied number of observations per subject) with 5 outcome variables. However, not all outcome variables are measures in each observations. I want to get means for each outcome variable the first time it is observed across subjects.

Therefore, using first.id does not work (the first observation per subject doesn't necessarily have the first measure of that outcome).

Any ideas?

doing

IF first.id AND first.outcome then output

does not work either.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LGrau

11-15-2017 10:52 PM

Relatively trivial to accomplish this, here are the steps.

1. Create flags for each measure, set to 0

2. If this is the first non missing and flag is not set, store it to a new variable and set flag

3. At first iteration of each group set flags and values back to missing.

If you need further help, provide data in a data step so that we can work with data. It doesn't need to exactly your data but needs to reflect what you have.

LGrau wrote:

Hi everyone,

I have a data set in long format (varied number of observations per subject) with 5 outcome variables. However, not all outcome variables are measures in each observations. I want to get means for each outcome variable the first time it is observed across subjects.

Therefore, using first.id does not work (the first observation per subject doesn't necessarily have the first measure of that outcome).

Any ideas?

doing

IF first.id AND first.outcome then output

does not work either.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

11-16-2017 09:43 AM

I'm sorry, I'm not sure what you mean by flags. Here's a sample data set. As you can see, some outcomes are missing until the third observation on the same person. I would need to find the means each outcome the first time it is recorded in each individual.

DATA WORK.SOURCE;

INFILE DATALINES DELIMITER= ',' DSD MISSOVER;

INPUT

SubjID

TxGrp :$5.

SexCd :$1.

EthCd

Outcome1

Outcome2

Outcome3;

DATALINES;

101,Arm A,F,1,45,,

101,Arm A,F,1,,3,2

101,Arm A,F,1,43,4,

102,Arm C,M,1,,5,,

102,Arm C,M,1,,4,3

102,Arm B,M,2,32,2,5

;

Solution

11-16-2017
12:34 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LGrau

11-16-2017 11:00 AM