I am attempting to complete LAG function. I can get it to work for numbers and dates, but it doesn't seem to work with String data. Here is my syntax- it runs and nothing happens. I do not get an error message in Output. What am I missing?? if (RandomID eq lag (RandomID)) and Missing (Dischargereason) Dischargereason=lag(Dischargereason). Here is what the data look like- I want ‘treatment complete’ to be copied for the 3 lines under the first line for randomIDs 12345, and facility transfer to be copied for randomIDs 14561 randomID Dischargereason 12345 treatment complete 12345 12345 12345 13456 administrative change 13456 13464 treatment complete 14561 facility transfer 14561 14561 14561 Vicki L. Stirkey OMHSAS l Bureau of Quality Management and Data Review 112 East Azalea Drive l Hbg PA 17110 Phone: 717.705.8198 l Fax: 717.772.6737 |
DischargeReason is a string variable and you have to define the missing value designator value, which here would be ‘ ‘ where you have a many blanks as width of the variable. Better to say this. if (RandomID eq lag (RandomID) and Dischargereason eq ‘ ‘) Dischargereason=lag(Dischargereason). or this if (RandomID eq lag (RandomID) and char.length(Dischargereason) eq 0) Dischargereason=lag(Dischargereason). Gene Maguin From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Stirkey, Vicki I am attempting to complete LAG function. I can get it to work for numbers and dates, but it doesn't seem to work with String data. Here is my syntax- it runs and nothing happens. I do not get an error message in Output. What am I missing?? if (RandomID eq lag (RandomID)) and Missing (Dischargereason) Dischargereason=lag(Dischargereason). Here is what the data look like- I want ‘treatment complete’ to be copied for the 3 lines under the first line for randomIDs 12345, and facility transfer to be copied for randomIDs 14561 randomID Dischargereason 12345 treatment complete 12345 12345 12345 13456 administrative change 13456 13464 treatment complete 14561 facility transfer 14561 14561 14561 Vicki L. Stirkey OMHSAS l Bureau of Quality Management and Data Review 112 East Azalea Drive l Hbg PA 17110 Phone: 717.705.8198 l Fax: 717.772.6737 |
Administrator
|
In reply to this post by vstirkey
if (RandomID eq lag (RandomID)) and Missing (Dischargereason) Dischargereason=lag(Dischargereason).
Verify that you have actually declared missing values for Dischargereason FREQ Dischargereason . There should be a row for the blanks prefixed by Missing . Barring that, the IF will fail due to " " NOT being the same as MISSING. So: use MISSING VALUES Dischargereason (" "). and run as before (maybe salt it with an EXECUTE for testing purposes). OR WITHOUT missing values statement: if (RandomID eq lag (RandomID)) and (Dischargereason EQ " ") Dischargereason=lag(Dischargereason).
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?" |
In reply to this post by vstirkey
Vicki, Missing doesn’t work with string variables. Try this syntax. if (RandomID eq lag (RandomID)) and len(ltrim(Dischargereason))=0) Dischargereason=lag(Dischargereason). Brian From: SPSSX(r) Discussion [mailto:[hidden email]]
On Behalf Of Stirkey, Vicki I am attempting to complete LAG function. I can get it to work for numbers and dates, but it doesn't seem to work with String data. Here is my syntax- it runs and nothing happens. I do not get an error message in Output. What am I missing?? if (RandomID eq lag (RandomID)) and Missing (Dischargereason) Dischargereason=lag(Dischargereason). Here is what the data look like- I want ‘treatment complete’ to be copied for the 3 lines under the first line for randomIDs 12345, and facility transfer to be copied for randomIDs
14561 randomID Dischargereason 12345 treatment complete 12345 12345 12345 13456 administrative change 13456 13464 treatment complete 14561 facility transfer 14561 14561 14561 Vicki L. Stirkey OMHSAS
l
Bureau of Quality Management and Data Review Phone: 717.705.8198
l
Fax: 717.772.6737 |
Administrator
|
"Missing doesn't work with string variables. "
Sure it does ;-) data list / x (a80). begin data abcsdefegg dffgggdhhh end data. MISSING VALUES x (" "). COMPUTE y=MISSING(x). LIST. x y abcsdefegg .00 1.00 dffgggdhhh .00 Number of cases read: 3 Number of cases listed: 3 HOWEVER: MISSING VALUES x (" "). >Error # 4809 in column 19. Text: ' ' >The missing value exceeds 8 bytes. >Execution of this command stops. COMPUTE y=MISSING(x). From the FM: Limitations Missing values for string variables cannot exceed 8 bytes. (There is no limit on the defined width of the string variable, but defined missing values cannot exceed 8 bytes.)
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?" |
There is no such thing as a system-missing
string value -- but as Dave's example shows, you can define user-missing
string values, including an "empty" string value.
Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: David Marso <[hidden email]> To: [hidden email], Date: 06/04/2013 02:38 PM Subject: Re: Lag Question Sent by: "SPSSX(r) Discussion" <[hidden email]> "Missing doesn't work with string variables. " Sure it does ;-) data list / x (a80). begin data abcsdefegg dffgggdhhh end data. MISSING VALUES x (" "). COMPUTE y=MISSING(x). LIST. x y abcsdefegg .00 1.00 dffgggdhhh .00 Number of cases read: 3 Number of cases listed: 3 HOWEVER: MISSING VALUES x (" "). >Error # 4809 in column 19. Text: ' ' >The missing value exceeds 8 bytes. >Execution of this command stops. COMPUTE y=MISSING(x). From the FM: Limitations Missing values for string variables cannot exceed 8 bytes. (There is no limit on the defined width of the string variable, but defined missing values cannot exceed 8 bytes.) bdates wrote > Vicki, > > Missing doesn't work with string variables. Try this syntax. > > if (RandomID eq lag (RandomID)) and len(ltrim(Dischargereason))=0) > Dischargereason=lag(Dischargereason). > > Brian > ________________________________ > From: SPSSX(r) Discussion [mailto: > SPSSX-L@.UGA > ] On Behalf Of Stirkey, Vicki > Sent: Tuesday, June 04, 2013 3:02 PM > To: > SPSSX-L@.UGA > Subject: Lag Question > > I am attempting to complete LAG function. I can get it to work for numbers > and dates, but it doesn't seem to work with String data. > > Here is my syntax- it runs and nothing happens. I do not get an error > message in Output. What am I missing?? > > if (RandomID eq lag (RandomID)) and Missing (Dischargereason) > Dischargereason=lag(Dischargereason). > > Here is what the data look like- I want 'treatment complete' to be copied > for the 3 lines under the first line for randomIDs 12345, and facility > transfer to be copied for randomIDs 14561 > > randomID Dischargereason > 12345 treatment complete > 12345 > 12345 > 12345 > 13456 administrative change > 13456 > 13464 treatment complete > 14561 facility transfer > 14561 > 14561 > 14561 > > > Vicki L. Stirkey > OMHSAS l Bureau of Quality Management and Data Review > 112 East Azalea Drive l Hbg PA 17110 > Phone: 717.705.8198 l Fax: 717.772.6737 > www.dpw.state.pa.us<http://www.dpw.state.pa.us> ----- 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?" -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Lag-Question-tp5720559p5720567.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Free forum by Nabble | Edit this page |