On Thursday, June 11, 2020 at 12:07:20 AM UTC-4,
[email protected] wrote:
Hi there,
My dataset has multiple responses and I just need the first response for analysis. So all text after the | characters can be deleted.
I have 100 variables named OtherIssue_1 to OtherIssue_100 and would be good to have a loop rather than 100 pieces of syntax...but no idea how to do that.
OtherIssue_1
32
36
106|96
88
72|55
I want to look like this:
32
36
106
88
72
Many thanks
Erin
There might be some neater method that is not occurring to me right now, but this works on some sample data similar to what you showed.
* Version 1: Assuming you want new variables to be string.
DATA LIST FREE / OtherIssue_1 OtherIssue_2 (2A10).
BEGIN DATA
"32"
"36"
"106|96"
"88"
"72|55"
"9999|1234"
END DATA.
STRING new1 new2 (A10).
DO REPEAT old = OtherIssue_1 TO OtherIssue_2 / new = new1 TO new2.
COMPUTE #L = CHAR.INDEX(old,"|") - 1.
IF #L EQ -1 #L = LENGTH(RTRIM(old)).
COMPUTE new = CHAR.SUBSTR(old,1,#L).
END REPEAT.
LIST.
* Version 2: Assuming you want new variables to be numeric.
DATA LIST FREE / OtherIssue_1 OtherIssue_2 (2A10).
BEGIN DATA
"32"
"36"
"106|96"
"88"
"72|55"
"9999|1234"
END DATA.
NUMERIC new1 new2 (F8.0).
DO REPEAT old = OtherIssue_1 TO OtherIssue_2 / new = new1 TO new2.
COMPUTE #L = CHAR.INDEX(old,"|") - 1.
IF #L EQ -1 #L = LENGTH(RTRIM(old)).
COMPUTE new = NUMBER(CHAR.SUBSTR(old,1,#L),F8).
END REPEAT.
LIST.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)