使用char.sub命令处理多个变量

huangapple go评论57阅读模式
英文:

Using char.sub command on multiple variables

问题

我必须选择多个变量中以特定数字开头的一组案例。

我正在使用以下代码:

CHAR.SUBSTR(variable1,1,x) ="y" | CHAR.SUBSTR(variable2,1,x) ="y" .............| CHAR.SUBSTR(variable40,1,x) ="y".

(x是字符数,y是我选择的字符),这些变量的名称相似,只有数字1到40不同。

这个方法有效,但问题是有40个变量,代码非常冗长。有没有更优雅的方式来编写它?比如 variable1 到 variable 40?

英文:

I have to select group of cases starting with specific numbers in multiple variables.

I am using this
CHAR.SUBSTR(variable1,1,x) ="y" | CHAR.SUBSTR(variable2,1,x) ="y" .............| CHAR.SUBSTR(variable40,1,x) ="y".

(x is number of character,y is characters I am choosing) the variables are named similar with just the number 1 to 40 being different

it works but problem is there are 40 variables and code is very length.
any elegant way to write it? like variable1 THRU variable 40?

答案1

得分: 1

你可以循环遍历变量,然后进行选择。就像这样:

do repeat vr=variable1 to variable40.
  if CHAR.SUBSTR(vr,1,1)="y" keep_this=1.
end repeat.
select if keep_this=1.

运行循环后,如果任何变量以 "y" 开头,那么该行将在变量 keep_this 中标记为 1。现在你可以仅选择 keep_this=1 的案例。

英文:

You can loop through the variables and then select. Like this:

do repeat vr=variable1 to variable40.
  if CHAR.SUBSTR(vr,1,1)="y" keep_this=1.
end repeat.
select if keep_this=1.

after running the loop, if any of the variables starts with "y" then the line will be marked with 1 in the variable keep_this. Now you can select only cases where keep_this=1.

huangapple
  • 本文由 发表于 2020年1月3日 18:24:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576870.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定