And here is both the first part and the second (removing commas):
data list list /v1 to v3 (3A8).
begin data.
323521 . .
. 336258 .
452521 . .
. . 515485
Bob . .
95852 . .
555548 . .
. AC222585 .
"13,456" . .
end data.
vector v=v1 to v3.
string newvar (A8).
loop #i=1 to 3.
* in any v(#i), replace ',' with a ''. .
compute v(#i)=replace(v(#i),",",'').
if any(char.substr(v(#i),1,1),'3','4','5') newvar=v(#i).
end loop.
execute.
list.
------------------------------
Rick Marcantonio
Quality Assurance
IBM
------------------------------
Original Message:
Sent: Thu September 22, 2022 03:00 PM
From: Art Jack
Subject: Loops & Vectors
Hi Rick, Anytime v1 to v3 starts with a 3,4, or 5 I want to create a variable that equals the whole cell of v1 to v3. But I don't want to copy fields that don't start with those numbers. But I need to this for V0 to V144. - thanks.
v1 | v2 | v3 | new_variable |
323521 | | | 323521 |
336258 | | | 336258 |
| 452521 | | 452521 |
| 515485 | | 515485 |
Bob | | | |
| 95852 | | |
| | 555548 | 555548 |
| | AC222585 | |
------------------------------
Art Jack
Original Message:
Sent: Thu September 22, 2022 02:52 PM
From: Rick Marcantonio
Subject: Loops & Vectors
Sorry, but like usual I'm unclear about exactly what you want to see.
"variables start with a 3 4 or 5 and then copy that whole variable into a new one."
Copy the value of each variable that begins with any(3,4,5) into a new (numeric) variable that contains that value? So, for each case, there could possibly be 145 new numeric variables (if each of V0 to v144 begin with any(3,4,5))?
Can you please provide me an example of what you expect to see when whatever code is used runs as you want it to?
------------------------------
Rick Marcantonio
Quality Assurance
IBM
Original Message:
Sent: Thu September 22, 2022 02:34 PM
From: Art Jack
Subject: Loops & Vectors
Afternoon,
I need to go through multiple columns and identify which variables start with a 3 4 or 5 and then copy that whole variable into a new one. I also need to run loops through these to replace ',' with a ''. I was thinking something like this below.
vector file=V0 to V144.loop i=1 to 14.
if char.substr(i, char.index(i, '3', '4', '5')) file=i.'
compute i=replace(',','').
end loop.
execute.
------------------------------
Art Jack
------------------------------
#SPSSStatistics