BookmarkSubscribeRSS Feed
DavidsM
Calcite | Level 5

Hello community,

 

I have a very large data set with many years of repeatedly measured data an over 180 variables per observations. I want to impute missing data for the first two years but converting these variables to wide format to capture record for every time of measurement and then impute is extremely tasking and the imputations are computationally demanding.

 

Is there any way to directly impute longitudinal data in long format using sas? 

 

I will be glad to be advised and assisted and I wish to use FCS method in the imputaion.

 

Thank in advance

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

Are the missing variables  continuous ? 

An example of the before/after data would be nice too.

DavidsM
Calcite | Level 5

 

 

The are both continuous an categorical variables. The data is arranged with person 

 

 

Data structure before

 

ID    YEAR    WEIGHT    HEIGHT     SMOKING    EXERCISE

 

01    2000           .              175                   .                  1

01    2001           57           175                  1                  1

01    2002           .              175                   .                  1

01    2003           57           175                  1                  1

01    2004           .              175                   .                  1

02    2000           57             .                     1                  1

02    2001           .              168                  .                  1

02    2004          57            169                  1                  1

 

 

Data structure after(Only one observation per person with missing values for year 2000 values imputed .

 

 

ID    YEAR    WEIGHT2000   HEIGHT2000   SMOKING2000    EXERCISE2000

01    2000            57               175                           1                          1

02    2000            57                168                          1                          1

 

 

 

I want to have the values for the first year imputed so that I use the information for the first year in my analysis. There many observations per person and the number of observations is not similar but I want to have one summary of imputed data for each person(One entry per person).

 

Thank you for assistance. 

 

 

 

 

 

 

 

ScottBass
Rhodochrosite | Level 12

I can help with your issue, but first edit your original post with a self-contained data step using datalines, posted using "Insert SAS code", that I can cut-and-paste into SAS and run without error.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
DavidsM
Calcite | Level 5

DATA HAVE;
INPUT       ID     YEAR      WEIGHT     HEIGHT     SMOKING    EXERCISE
DATELINES;

            01      2000        .          175          .        1

            01      2001        57         175          1        1

            01      2002        .          175          .        1

            01      2003        57         175          1        1

            01      2004        .          175          .        1

            02      2000        57         .            1        1

            02      2001        .          168          .        1

            02      2004        57         169          1        1
   
 



DATA HAVE;
INPUT      ID    YEAR  WEIGHT  HEIGHT SMOKING EXERCISE
DATELINES;

           01    2000    57    175      1     1

           02    2000    57    168      1     1

ChrisNZ
Tourmaline | Level 20

This program is not even close to being error free.

So you want a perfectly working program that answers your question but can't be bothered supplying a working sample program?

Also why only one year in the output? Do you take the minimum non-missing value of all variables? Is this how you want to impute?

ScottBass
Rhodochrosite | Level 12

@ChrisNZ wrote:

This program is not even close to being error free.

So you want a perfectly working program that answers your question but can't be bothered supplying a working sample program?

Also why only one year in the output? Do you take the minimum non-missing value of all variables? Is this how you want to impute?


Yep, I completely agree with Chris.  I know how to code this issue - it may not be perfect but would work - but refuse to expend more effort in answering your question than you (twice) expended in posting it. 

 

Once you learn what cut-and-paste working code into SAS means, perhaps you'll get a working reply.

 

Here are some hints:

 

  • Transpose
  • Filter non-missing values
  • Select minimum year with non-missing values
  • Transpose again
  • Set that year to a dummy value, say year 0
  • Interleave with your existing data
  • Use update statement to do LOCF.
  • Transpose again to name your data as FOO2000, FOO2001, etc

See, wouldn't this have been so much easier if you'd provided working code that we could run with.

 

Hit Google or search these forums for working examples of all the above.  I'm sure you'll work it out eventually.

 

Good luck, I'm unsubscribing from this one...


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 6 replies
  • 911 views
  • 1 like
  • 3 in conversation