DATE
11996
11295
91295
90495
of which I did find out that the leading zeros were truncated (data was entered in dBase3)......so in attempting to create a year variable I employed the following strategy:
...I converted the numeric date into a A6 length string variable (date), then used the following syntax:
compute month=substr(date,1,2).
compute day =substr(date,3,2).
compute year=substr(date,5,2).
execute.
I get the following error message:
compute month=substr(date,1,2).
>Error # 4309 in column 256. Text: (End of Command)
>Invalid combination of data types in an assignment. Character strings may
>only be assigned to string variables. Numeric and logical quantities may
>only be assigned to numeric variables. Consider using the STRING or NUMBER
>function.
>This command not executed.
execute.
For some reason, the variable "date", which was indeed converted into a string variable, is not being recognized as such.....I have tried multiple strategies, including keeping the variable numeric and attempting to segment it into month, day, and year accordingly, but it seems that with SPSS you have to start with a string variable in order to do that....I thought possibly the problem was the lack of leading zeros, so I attempted using options such as:
compute newdate=LPAD(date,1,'0').
execute.
but same error message.......hmmmmmm any suggestions........?
take care and thank you!!!
dale glaser
You need to tell SPSS before the compute statement that the variable MONTH
will be a string variable and how wide it will be, as in:
STRING month (A2).
COMPUTE month=SUBSTR(date,1,2).
But, if you would rather have MONTH be a numeric variable, then you
should use this command (instead of the two above):
COMPUTE month=NUMBER(SUBSTR(date,1,2),F2.0).
-Dawn
--
Dawn Owens-Nicholson, Data Archivist
Ofc of Computing & Communications for the Social Sciences, Univ. of Illinois
212 Lincoln Hall MC-460, 702 S. Wright St., Urbana, IL 61801
Tel: (217) 333-7751 Fax: (217) 333-2869 Email: blue...@uiuc.edu
in contrast to numeric variables, when computing new *string* variables, you have to first declare their existence prior to performing any action on them.
so, your syntax is correct (i think - i didn't check really closely), just preceed the whole set with the following:
string newdate (a8).
<spss substring commands here>.
execute.
hope this helps.
fj
Dale Glaser wrote:
> <snip>
> ...I converted the numeric date into a A6 length string variable (date), then used the following syntax:
>
> compute month=substr(date,1,2).
> compute day =substr(date,3,2).
> compute year=substr(date,5,2).
> execute.
>
> I get the following error message:
>
> compute month=substr(date,1,2).
>
> >Error # 4309 in column 256. Text: (End of Command)
> >Invalid combination of data types in an assignment. Character strings may
> >only be assigned to string variables. Numeric and logical quantities may
> >only be assigned to numeric variables. Consider using the STRING or NUMBER
> >function.
> >This command not executed.
>
> execute.