Remove double quotes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
* Data (variable v1) is enclosed in double quotes. * Want to remove quotes en each side of data. * email@example.com. ***********Method 1. *### First situation: the data inside the quote is a number. *convert the quote enclosed data (say variable v1) to the numeric variable as v3 follows. COMPUTE v2=NUMBER(SUBSTR(v1,2,RINDEX(v1,'"')-2),F8.2). *Note that the second argument of the RINDEX function is a " enclosed in 2 ' (2 single quotes). *### Second situation: the data inside the quotes is a string. *Assuming v1 is a string variable, get rid of the double quotes as follows: * (The length of v4 must be at most 2 bytes smaller than the length of v1) STRING v4(A8). COMPUTE v4=SUBSTR(v1,2,RINDEX(v2,'"')-2). ************* Method 2. * To remove beginning and ending quotes from string (many string variables). * This is more general than method 1, since single and double quotes are automatically removed. * list your variables after the = sign in the next line. DO REPEAT vname=name sex city. * Note: in next command, #len is the number of characters between the 2 quotes . * this method can be used to delete ANY useless character at both the beginning and end of all values. compute #len = rindex(vname,substr(vname,1,1))-2. compute vname=substr(vname,2,#len). END REPEAT. execute.