Jump to content

Anyone Out There An Spss Whiz?


Sheryl

Recommended Posts

Nothing specific to Thailand but I'm assuming this forum is where computer geeks hang out and hoping amongst you there's one very proficient in use of SPSS (statistical program).

I have wasted 3 days time trying to do something and apparently just can't get the syntax right altho I've tried every permutation I can think of.

Problem: I have 2 numerical variables which I need to string together into a new string variable. This I know how to do using the CONCAT string function. But I am stumped in use of the LTRIM function to remove leading zeros.

EX: var 1 is 3 (2 digit variable) variable 2 is 45 (in a 3 digit variable), I need to produce the string variable 3 45.

Instead I get 03 045.

I have tried putting the LTRIM command (variable name, "0") into the same line as the CONCAT command and also separaetly as a 2 stage process (first turning each of the 2 numerical variables into a string variable and then concatenating them). No matter what I seem to do vis-a-vis paranthesis, commas etc I get error messages. :o

My undying gratitutde to anyone who can help out......

Link to comment
Share on other sites

OK, if the result is 03 045, the first problem I see is the <space>, is this coming from var 1 or 2 or is it typographical?

Do you really want to produce 3 45 or 345 or 3.45 ?

Forgive me I'm not a Spss wiz or any other one I guess, but please clarify what you want to receive in var R. By the by what error do you receive?

Regards

Link to comment
Share on other sites

OK, if the result is 03 045, the first problem I see is the <space>, is this coming from var 1 or 2 or is it typographical?

Do you really want to produce 3 45 or 345 or 3.45 ?

Forgive me I'm not a Spss wiz or any other one I guess, but please clarify what you want to receive in var R. By the by what error do you receive?

Regards

The space is intentional. I want 3 45, so my CONCAT command was for (var1), "", (var2).

As to what error message it varies with the syntax I try. Sometimes it doesn't recognize LTRIM as an SPSS command. Sometimes it doesn't recognoze the zero in LTRIM(variablename,"0"). Sometimes it seems to have an issue with the placement of commas or parentheses. If anyone out there is familiar with using the LTRIM function I can show what syntax I have used and maybe you can advise what the problem is. Using CONCAT without any LTRIM of course gets me 003 45 instead of 3 45. But syntax for LTRIM seems a well kept secret....

Link to comment
Share on other sites

Does Spss define/declare variables on the fly? In other words must a} a variable be created before action is taken, and b} must a variable be typed [numeric, string] prior to action?

Generically I'd expect Ltrim( [string]variable, "0") --> Compute destination_var=(ltrim, var1, "0") Does that work?

Regards

edit [string]

Edited by A_Traveller
Link to comment
Share on other sites

This should be the correct syntax to accomplish what you want.

COMPUTE newvar = CONCAT(rtrim(ltrim(var1))," ",rtrim(ltrim(var2)).

The rtrim removes trailing blanks/spaces that may crop up. You can replace the (var1) and (var2) with (var1,"0") and (var2,"0") if the first instance doesn't work. Note: the numerical needs to be converted to strings first.

Link to comment
Share on other sites

Twais, my hero!!!!!!! After changing the original variables to string via the variable view screen and using exactly that syntax it worked.

Owe you one.....

:o

Once again TV saves the day, I should have thought to post here 2 days back. Instead of wasting time with the %^&$ help index....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.




×
×
  • Create New...