|
Hi,
I would like to calculate the variabel "freq". I want to calculate how many years VAR1 have had with "AA"(VAR2) in row. EX1. X have had "AA" 2 years in row (latest), we stop calculating when we have someting other than "AA". EX2. Y have only "AA" that would be 5 years EX3. Z have had "AA" 4 years in row Can someone please write a syntax to calculate "freq". Thanks in advance VAR1 VAR2 freq year X AA 1 2008 X AA 2 2007 X A - 2006 X AA - 2005 X AA - 2004 Y AA 1 2008 Y AA 2 2007 Y AA 3 2006 Y AA 4 2005 Y AA 5 2004 Z AA 1 2008 Z AA 2 2007 Z AA 3 2006 Z AA 4 2005 Z B - 2004 |
|
Administrator
|
I will direct you to look at the AGGREGATE command!
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
|
Ok, but if I aggregate var1 and var2 give X=4. But it would be X=2 since you have an "A" 2006. I just want to aggregate "AA" after each other.
|
|
Administrator
|
OK, Missed that first part ;-)
Note the magic here is driven by the special properties of #scratch variables. -- DO IF ( $CASENUM=1 OR var1 NE lag(var1) AND VAR2 EQ "AA" ). + COMPUTE xx=1. + COMPUTE #is_AA=1. END IF. IF VAR2 NE "AA" #is_AA=0. IF #is_AA AND var1 EQ lag(var1) xx=lag(xx)+1. AGGREGATE OUTFILE * MODE ADDVAR / BREAK VAR1 / FREQ=MAX(xx). BTW: Please delete your second (duplicated) post of this topic.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
| Free forum by Nabble | Edit this page |
