从字符串中去掉撇号(压缩?)
我有一个看起来像这样的字符串:
"ABAR_VAL", "ACQ_EXPTAX_Y", "ACQ_EXP_TAX", "ADJ_MATHRES2"
我希望它看起来像这样:
ABAR_VAL ACQ_EXPTAX_Y ACQ_EXP_TAX ADJ_MATHRES2
即没有撇号或逗号和单个空格分隔。
在 SAS 9.1.3 中最干净/最短的方法是什么?
最好是这样的:
call symput ('MyMacroVariable',compress(????,????,????))
为了清楚起见,结果需要以单个空格分隔,没有标点符号,并且包含在宏变量中。
I have a string which looks like this:
"ABAR_VAL", "ACQ_EXPTAX_Y", "ACQ_EXP_TAX", "ADJ_MATHRES2"
And I'd like it to look like this:
ABAR_VAL ACQ_EXPTAX_Y ACQ_EXP_TAX ADJ_MATHRES2
I.e. no apostrophes or commas and single space separated.
What is the cleanest / shortest way to do so in SAS 9.1.3?
Preferably something along the lines of:
call symput ('MyMacroVariable',compress(????,????,????))
Just to be clear, the result needs to be single space separated, devoid of punctuation, and contained in a macro variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
干得好..
Here you go..
这是 infile 语句的一部分,还是您确实想要创建包含这些值的宏变量? 如果这是 infile 语句的一部分,并且正确设置了分隔符,则不需要执行任何操作。
是的,您确实可以使用 compress 函数从字符串中删除特定字符,无论是在数据步骤中还是作为宏调用的一部分。
示例数据:
解决数据步骤中的问题(而不是创建宏变量):
在生成宏变量时解决问题:
如果您使用,您将必须循环遍历观察结果才能查看每个记录的变量的压缩值后面的代码。 :)
Is this part of an infile statement or are you indeed wanting to create macro variables that contain these values? If this is part of an infile statement you shouldn't need to do anything if you have the delimiter set properly.
And yes, you can indeed use the compress function to remove specific characters from a character string, either in a data step or as part of a macro call.
Sample Data:
Resolve issue in a data step (rather than create a macro variable):
Resolve issue whilst generating a macro variable:
You'll have to loop through the observations in order to see the compressed values the variable for each record if you use the latter code. :)
要将多个空白压缩为一个,请使用 compbl : http://www. technion.ac.il/docs/sas/lgref/z0214211.htm
To compress multiple blanks into one, use compbl : http://www.technion.ac.il/docs/sas/lgref/z0214211.htm