SPSS Statistics

 View Only

 LTRIM

Patrick Fisher's profile image
Patrick Fisher posted Fri February 20, 2026 07:13 PM
COMPUTE NewStringVar = LTRIM(OldStringVar).
EXECUTE.

That does not work. It was suggested by Google AI as a fix.

SPSS is trying to tell me that I'm attempting to do this with conflicting variables (string-numeric). I'm not. I converted my numeric variable into a string variable to get around this problem.

I have 6 and 7 leading spaces in front of my 1-80 data in my variable.

How do I get rid of those spaces?

Thanks,

Patrick

Jon Peck's profile image
Jon Peck IBM Champion

SPSS. Is complaining that the right hand side is a string but the left would be numeric.  You need to declare it with the STRING command before the COMPUTE

Bruce Weaver's profile image
Bruce Weaver

Hello Patrick.  You say you 6 and 7 leading spaces in front of your 1-80 data.  What does that mean exactly?  My best guess (right now) is OldStringVar holds the numbers 1 to 80 (as strings), and that there are 7 leading blanks for 1-digit "numbers" and 6 leading blanks for 2-digit "numbers".  In other words, OldStringVar is formatted as A8.  Is that right?  If so, why do you need to keep a version of the variable that retains the leading blank spaces?  Why not just overwrite the variable, like this:

COMPUTE OldStringVar = LTRIM(OldStringVar).

If you do need both versions for some reason, then you will have to do what Jon suggested:

STRING NewStringVar (A8).
COMPUTE NewStringVar = LTRIM(OldStringVar).

Meanwhile, I find myself wondering if this is an example of the so-called XY problem.  I.e., I wonder if you are asking how to carry out your intended solution to some problem without explaining what the actual problem is.  If you explain clearly what the actual problem is, someone may be able to offer another solution.  

Cheers,
Bruce