Hi all,
I have a problem with data. I want to create a new variable like "dd" here is my dataset, each column presents a variable, a b dd 23 . 23/20 20 20 20/20 45 . 45/12 15 . 15/12 33 . 33/12 40 . 40/12 20 12 20/12 here is my question. There is a table with 3 variables. The last one "dd" created later. The "b" at the first raw is empty. I want to consider the next filled "b" value to divide 23 at the first raw and column. For instance, 45 at the third raw. I want to go till I see a filled value, "12" to divide. What is the syntax for this? |
Administrator
|
I don't have access to SPSS right now, so this is untested. It assumes that the last record in your actual file has a valid value for variable b.
STRING dd (A5). COMPUTE @order = $casenum. SORT CASES by @order(d). IF NOT MISSING(b) #b = b. COMPUTE dd = CONCAT(STRING(a,N2), "/", STRING(#b, N2)). EXECUTE. SORT CASES by @order(a). DELETE VARIABLES @order. Note that scratch variables (e.g., #b) retain their value from one case to the next, so once #b has been set equal to b, it retains that value until the next valid b occurs. HTH.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
Using AGGREGATE
IF $CASENUM=1 #=1. IF NOT(MISSING(Lag(b))) #=#+1. COMPUTE GP=#. AGGREGATE OUTFILE * MODE=ADDVARIABLES / BREAK GP / new=LAST(b). Do whatever you need to do with the result. I don't see any practical use for a variable formatted as 21/12 or such...Whatever rocks your world.
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?" |
thx David,
It is 21 divided by 12. it will be a new variable. Otherwise it is meaningless :) |
Administrator
|
In that case, the syntax I posted earlier should be changed to:
COMPUTE @order = $casenum. SORT CASES by @order(d). IF NOT MISSING(b) #b = b. COMPUTE dd = a/#b. EXECUTE. SORT CASES by @order(a). DELETE VARIABLES @order.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Free forum by Nabble | Edit this page |