我使用这些函数来计算单词countw
,并使用单词scan
来分析完整的文件名。 (对于那些感兴趣的人,我通常使用FILENAME docDir PIPE "dir ""&docRoot"" /B/S";
)
使用传统的SAS,这适用于UNIX和Windows:
data OLD_SCHOOL;
format logic withSlash withBack secondSlash secondBack $20.;
logic = 'OLD_SCHOOL';
withSlash = 'Delimited/With/Slash';
wordsSlash = countw(withSlash, '/');
secondSlash = scan(withSlash, 2, '/');
withBack = 'Delimited\With\Back';
wordsBack = countw(withBack, '\');
secondBack = scan(withBack, 2, '\');
worksTheSame = wordsSlash eq wordsBack and secondSlash eq secondBack;
put _all_;
run;
结果
withSlash=Delimited/With/Slash secondSlash=With wordsSlash=3
withBack=Delimited\With\Back secondBack=With wordsBack=3
worksTheSame=1
使用较新的DS2语法,scan和countw处理反斜杠的方式不同
proc ds2;
data DS2_SCHOOL / overwrite=yes;
dcl double wordsSlash wordsBack worksTheSame;
dcl char(20)logic withSlash withBack secondSlash secondBack;
method init();
logic = 'DB2_SCHOOL';
withSlash = 'Delimited/With/Slash';
wordsSlash = countw(withSlash, '/');
secondSlash = scan(withSlash, 2, '/');
withBack = 'Delimited\With\Back';
wordsBack = countw(withBack, '\');
secondBack = scan(withBack, 2, '\');
worksTheSame = (wordsSlash eq wordsBack) and (secondSlash eq secondBack);
end;
enddata;
run;
quit;
data BOTH_SCHOOLS;
set OLD_SCHOOL DS2_SCHOOL;
run;
结果
withSlash=Delimited/With/Slash secondSlash=With wordsSlash=3
withBack=Delimited\With\Back secondBack= wordsBack=1
worksTheSame=0
这是否有充分的理由,或者我应该将其作为SAS的错误报告?
(正则表达式中可能存在反斜杠作用的链接。)
答案 0 :(得分:1)
我在9.3中验证了这一点(缺少覆盖=是,作为旁注,令人讨厌):
"ports": [
{
"port":80,
"targetPort": "8080",
"name":"check-server"
}
反斜杠确实似乎是一种逃避 - 即使在原始字符串中你需要一对它们。
从9.4 TS1M3开始不再是这种情况,因此不清楚9.3 TS1M2和9.4 TS1M3之间的位置是如何更改和/或修复的 - 并且在任何更改日志中都没有提及,不幸的是。
根据评论/验证,它看起来特别是在9.4 TS1M2中被更改/修复。
答案 1 :(得分:1)
谢谢乔。为了进一步证明你做对了:如果我在旧的学校数据步骤中指定我的字符串:
Data FROM_OLD_SCHOOL;
delimiter = '/';
fullName = 'Delimited/With/Slash';
output;
delimiter = '\';
fullName = 'Delimited\With\Back';
output;
run;
我可以在DS2数据步骤中完美地使用它们:
proc ds2;
data DS2_SCHOOL / overwrite=yes;
dcl double partsPresent;
dcl char(20) secondPart;
method run();
set FROM_OLD_SCHOOL;
partsPresent = countw(fullName, delimiter);
secondPart = scan(fullName, 2, delimiter);
end;
enddata;
run;
quit;
结果
Obs partsPresent secondPart delimiter fullName
1 3 With / Delimited/With/Slash
2 3 With \ Delimited\With\Back