Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • subtracting year from a non-numeric variable

    Dear all,

    i have a variable called E, which is the completed date of an acquisition (see screenshot). The variable is non-numeric string and in %14s format. De date in the variable is displayed as follows:
    11jan2001. Now I want to created a new variable called fyear and subtract the last four digits (=year of acquisition) from the E variable. I've got problems doing this because the variable is non-numeric. Is there anyone who can help me?

    Thanks in advance!
    Click image for larger version

Name:	Schermafbeelding 2021-05-17 om 12.06.08.png
Views:	1
Size:	433.1 KB
ID:	1610049

  • #2
    This data set does not seem to be imported correctly. The variable name is showing "E" but the actual name should have been "Completed date". Please first try to import it one more time, look for check box option saying something in the line of "The first row contains variable names". If the problem persists, you can use the following script to extract it:

    Code:
    gen sfyear = regexs(1) if regexm(E, "([0-9][0-9][0-9][0-9])")
    gen fyear = real(sfyear)
    Last edited by Ken Chui; 17 May 2021, 06:42.

    Comment

    Working...
    X