Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

Counting duration of each spell

Reply

Counting duration of each spell

Hi all,

I am trying to calculate the number of spells, lenght of spell, and duration of each spell for each partner at commodity level. Spell is defined as the period where the home country has positive imports from partner. I am trying to create the output at yearly basis so that I can calculate duration of each spell (remaining years from begining of the spell to the ending of each spell). I have put a desired output for my analysis but I couldnt achieve it using your SAS code. I will appreciate if you help me on this issue. Thank you very much. I have very large dataset, around 300 million observations. So I need very efficient code to solve my problem.

Best wishes,

Kemal Turkcan,

DESIRED OUTPUT (only for one commodity)

year  partner commodity imports spell totalnumberofspells  lenghtofspell duration    mean minspell    maxspell

1996  757 110429      1 1     2     1 1     3     1     5

1997  757 110429      0 .     2     . .     3     1     5

1998  757 110429      0 .     2     . .     3     1     5

1999  757 110429      0 .     2     . .     3     1     5

2000  757 110429      0 .     2     . .     3     1     5

2001  757 110429      0 .     2     . .     3     1     5

2002  757 110429      0 .     2     . .     3     1     5

2003  757 110429      0 .     2     . .     3     1     5

2004  757 110429      0 .     2     . .     3     1     5

2005  757 110429      1 2     2     5 5     3     1     5

2006  757 110429      1 2     2     5 4     3     1     5

2007  757 110429      1 2     2     5 3     3     1     5

2008  757 110429      1 2     2     5 2     3     1     5

2009  757 110429      1 2     2     5 1     3     1     5

SAS CODE

DATA TRADE;

INPUT  year partner  commodity  imports; DATALINES;

1996  757 110429      1

1997  757 110429      0

1998  757   110429 0

1999  757 110429      0

2000  757 110429      0

2001  757 110429      0

2002  757 110429      0

2003  757 110429      0

2004  757 110429      0

2005  757 110429      1

2006  757 110429      1

2007  757 110429      1

2008  757   110429 1

2009  757 110429      1

1996  757 284410      0

1997  757 284410      0

1998  757 284410      0

1999  757 284410      0

2000  757 284410      0

2001  757 284410      0

2002  757 284410      1

2003  757 284410      0

2004  757 284410      0

2005  757 284410      0

2006  757 284410      0

2007  757 284410      0

2008  757 284410      0

2009  757 284410      0

1996  842 110429      0

1997  842 110429      1

1998  842 110429      1

1999  842   110429 1

2000  842 110429      1

2001  842 110429      1

2002  842 110429      1

2003  842 110429      1

2004  842 110429      1

2005  842 110429      1

2006  842 110429      1

2007  842 110429      1

2008  842 110429      1

2009  842   110429 1

1996  842 284410      1

1997  842 284410      0

1998  842 284410      0

1999  842 284410      0

2000  842 284410      0

2001  842 284410      1

2002  842 284410      1

2003  842 284410      1

2004  842 284410      0

2005  842   284410 1

2006  842 284410      1

2007  842 284410      1

2008  842 284410      1

2009  842 284410      1

; RUN;

Ask a Question
Discussion stats
  • 0 replies
  • 229 views
  • 0 likes
  • 1 in conversation