过程SQL SAS Basic

过程SQL SAS Basic,sas,proc-sql,Sas,Proc Sql,我想要一个答案 我的意见是: ABC123 我想要的输出是: 123ABC 如何使用Proc SQL以这种格式(即向后打印)打印输出?根据给出的信息,并假设所有数据的格式相同,您可以调整Proc SQL中的substr函数 data have; value='ABC123'; run; proc sql; create table want as select value, substr(value,4,4)||substr(value,1,3) as new_value

我想要一个答案

我的意见是:

ABC123
我想要的输出是:

123ABC 

如何使用Proc SQL以这种格式(即向后打印)打印输出?

根据给出的信息,并假设所有数据的格式相同,您可以调整Proc SQL中的substr函数

data have;
value='ABC123';
run;

proc sql;
create table want
as
select value, 
       substr(value,4,4)||substr(value,1,3) as new_value
  from have;
quit;

proc print data=want; run;

同样的函数也可以应用于数据步骤。

您可能需要使用trim来处理SAS存储在字符变量中的尾随空格

trim(substr(have,4))||substr(have,1,3)

如果您想要一种算法,可以处理任意长度、任意字母数、任意数字的相似字符串,我建议使用正则表达式修改输入字符串

outStr = prxChange("s/([A-z]+)([\d]+)/$2$1/", 1, inStr);
您可以在procsql中轻松地使用它

data test1;
  inStr = "ABCdef12345";
run;

proc sql;
  create table test2 as
  select prxChange("s/([A-z]+)([\d]+)/$2$1/", 1, inStr) as outStr
  from test1;
quit;

Base SAS包含一个函数REVERSE,该函数专用于反转字符串,可在proc sql和datastep中使用。请参见示例或此处:

输出:

Name    | Name_reversed
--------|--------------
Alfred  | derflA
Alice   | ecilA
Barbara | arabraB

等。

dbms名称please@ZaynulAbadinTuhin ... 是SAS软件中的一个模块,因此其默认方言是特定于SAS的,主要具有可用的SAS功能。
Name    | Name_reversed
--------|--------------
Alfred  | derflA
Alice   | ecilA
Barbara | arabraB