+ Reply to Thread
Results 1 to 3 of 3

Thread: Flattening a data set (newbie question)

Hybrid View

  1. #1
    Points: 1,436, Level: 21
    Level completed: 36%, Points required for next Level: 64

    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Flattening a data set (newbie question)

    I'm relatively new to SAS, so please forgive me if this has an entirely obvious answer. I've searched the Web extensively for the past several days and have come up empty for a solution.

    I have a data set that describes equipment, the date a piece of equipment went out of service for repairs, and the number of days it was out, eg:

    Code: 
    machine   start_dte     days_out
    92347     21feb2011     3
    45885     02mar2011     2
    I'd ultimately like to end up with a data set that represents each day of an outage as its own record, eg:

    Code: 
    machine   date
    92347     21feb2011
    92347     22feb2011
    92347     23feb2011
    45885     02mar2011
    45885     03mar2011
    I'm wondering if anyone can suggest how I might achieve this. I'm open to anything. Using SAS EG 4.1

    Many thanks in advance for any help you can provide!

  2. #2
    TS Contributor
    Points: 6,949, Level: 54
    Level completed: 99%, Points required for next Level: 1

    Posts
    783
    Thanks
    0
    Thanked 71 Times in 70 Posts

    Re: Flattening a data set (newbie question)

    In this code, _DAYSREM is a counter (counting downard from the beginning value DAYS_OUT)--as long as _DAYSREM>0 you keep outputting a record.

    Code: 
    data outage;
    retain _daysrem;
    set equipment; *or whatever name of the dataset you are starting with;
    _daysrem = days_out;
    do while (_daysrem>0);
        date=start_dte+(days_out-_daysrem);
        output;
        _daysrem=_daysrem-1;
    end;
    drop _daysrem start_dte days_out;
    run;
    Last edited by Mean Joe; 03-28-2011 at 06:37 PM.

  3. #3
    Points: 1,436, Level: 21
    Level completed: 36%, Points required for next Level: 64

    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Flattening a data set (newbie question)

    This is perfect. Thanks very much, Joe! Worked perfectly.

+ Reply to Thread

Similar Threads

  1. newbie question
    By toothpicky in forum R
    Replies: 14
    Last Post: 03-03-2011, 03:59 PM
  2. Replies: 0
    Last Post: 11-05-2007, 07:09 AM
  3. Newbie need help! How to join/pool data.
    By kelly in forum Psychology Statistics
    Replies: 0
    Last Post: 10-17-2007, 10:14 AM
  4. Newbie with a question
    By TheQueenOfStyrene in forum Statistics
    Replies: 3
    Last Post: 10-12-2007, 08:10 PM
  5. Statistical test: newbie needs help on data analysis
    By Beyon in forum Psychology Statistics
    Replies: 1
    Last Post: 06-30-2006, 11:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats