Syntax for creating string variable with mean value + ui range from existing variables

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Syntax for creating string variable with mean value + ui range from existing variables

SPSSPeter
Dear all,

I have a file with three separate variables for the mean value, a lower and an upper estimate. From these three variables, I would like to create a string variable showing the mean value with the uncertainty interval as shown in this example:

Mean_value: 10
Lower_estimate: 8
Upper_estimate: 13

New_string_variable: "10 [8-13]"

Which syntax can I use for this purpose? Your help is greatly appreciated.
Best,

peter
Reply | Threaded
Open this post in threaded view
|

Re: Syntax for creating string variable with mean value + ui range from existing variables

David Marso
Administrator
See STRING command and STRING and CONCAT functions.
STRING New_string_variable (A10).
COMPUTE New_string_variable=CONCAT(STRING(Mean_value,F2)," [",STRING(Lower_estimate,F2),"-"........ etc...)
You can complete this as an exercise.

SPSSPeter wrote
Dear all,

I have a file with three separate variables for the mean value, a lower and an upper estimate. From these three variables, I would like to create a string variable showing the mean value with the uncertainty interval as shown in this example:

Mean_value: 10
Lower_estimate: 8
Upper_estimate: 13

New_string_variable: "10 [8-13]"

Which syntax can I use for this purpose? Your help is greatly appreciated.
Best,

peter
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?"
Reply | Threaded
Open this post in threaded view
|

Re: Syntax for creating string variable with mean value + ui range from existing variables

SPSSPeter
Dear David,

thank you very very much, this works, you saved me a lot of time, thanks! This syntax worked perfectly:

STRING value_with_ui_range (A100).
COMPUTE value_with_ui_range = CONCAT (LTRIM(STRING (value,F10.2)), " [",LTRIM(STRING (lower_estimate, F10.2)), "-", LTRIM(STRING (upper_estimate, F10.2)),"]").
EXECUTE.

Just one more question: this syntax gives me for the numeric value "0.12" the string value ".12" (without zero before the decimals) - ideally, I would like to get "0.12". Is there any easy way to accomplish this?

best, and thanks so much,

peter
Reply | Threaded
Open this post in threaded view
|

Re: Syntax for creating string variable with mean value + ui range from existing variables

David Marso
Administrator
Two basic solutions come to mind.
Use REPLACE function or conditionally prepend the strings.
Take your pick.

/* Use REPLACE */.
STRING value_with_ui_range (A100).
COMPUTE value_with_ui_range = CONCAT ((STRING (value,F10.2))," [", LTRIM(STRING (lower_estimate, F10.2)), "-", LTRIM(STRING (upper_estimate, F10.2)),"]").
DO REPEAT old=" ." "[." "-." / new="0."  "[0." "-0." .
COMPUTE value_with_ui_range=REPLACE(value_with_ui_range,old,new).
END REPEAT.

* Alternatively prepend the string *.
STRING value_with_ui_range (A100).
DO REPEAT nu=value lower_estimate upper_estimate / str= #v #l #u /del=" [" "-" "]".
STRING str (A10).
COMPUTE str=STRING(nu,F10.2).
IF (nu LT 1) str=CONCAT("0",LTRIM(str)).
COMPUTE  value_with_ui_range =CONCAT( RTRIM(value_with_ui_range),LTRIM(str),del).
END REPEAT.


SPSSPeter wrote
Dear David,

thank you very very much, this works, you saved me a lot of time, thanks! This syntax worked perfectly:

STRING value_with_ui_range (A100).
COMPUTE value_with_ui_range = CONCAT (LTRIM(STRING (value,F10.2)), " [",LTRIM(STRING (lower_estimate, F10.2)), "-", LTRIM(STRING (upper_estimate, F10.2)),"]").
EXECUTE.

Just one more question: this syntax gives me for the numeric value "0.12" the string value ".12" (without zero before the decimals) - ideally, I would like to get "0.12". Is there any easy way to accomplish this?

best, and thanks so much,

peter
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?"
Reply | Threaded
Open this post in threaded view
|

Re: Syntax for creating string variable with mean value + ui range from existing variables

SPSSPeter
the first solution you proposed worked perfectly fine, thanks a lot!
peter