Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何从SAS中的两列中提取不匹配字符_Sql_Sas - Fatal编程技术网

Sql 如何从SAS中的两列中提取不匹配字符

Sql 如何从SAS中的两列中提取不匹配字符,sql,sas,Sql,Sas,《SAS企业指南》中有两列,其中有一个字符列表。例如,第一列可能有7个字符,第二列也可能有7个字符,因此它们是匹配的。但是,有时列不匹配,我想将不匹配的字符放入新列中。 我已经尝试了find函数 proc sql; create table Z as select *, case when (act_route_path<>designed_route_path) then 'Non Match' else 'Match' end as

《SAS企业指南》中有两列,其中有一个字符列表。例如,第一列可能有7个字符,第二列也可能有7个字符,因此它们是匹配的。但是,有时列不匹配,我想将不匹配的字符放入新列中。 我已经尝试了find函数

   proc sql;
    create table Z
    as
    select *,
    case when (act_route_path<>designed_route_path) then 'Non Match'
    else 'Match' end as Off_at_Location_1
    from G;
    run;
proc-sql;
创建表Z
作为
选择*,
当(act_route_PathDesign_route_path)然后为“不匹配”时的情况
否则“匹配”在位置1处结束为关闭
从G;
跑
上面的代码运行时没有错误,但是我不希望bool true结果为“不匹配”。我想让它告诉我不匹配的字符。这在案例陈述中可行吗

我有两列,其中数据以(-)分隔,可以使用这两列作为输出

SEA-MDW-EFH-STL-------SEA-POR-MDW-EFH-STL


在上面的一行中,我希望SAS加入一个新的列,POR。谢谢你的帮助

你在找这种红色的东西吗

data g; 
    length act_route_path $ 2 designed_route_path $ 2;`
    input act_route_path $ designed_route_path $;
datalines;
    xx xy
    xx xx
    yy yy
    yx yy
;
run;

proc sql; create table z as
    select act_route_path, designed_route_path, 
        case when Off_at_Location_1 = 0 and substr2 = 0 then designed_route2 
            else 'Match' end as result
    from(select *
        ,case when act_route_path = designed_route_path then 1 else 0 end as Off_at_Location_1

        ,substr(act_route_path,1,1) as act_route1
        ,substr(act_route_path,1,2) as act_route2
        ,substr(designed_route_path,1,1) as designed_route1
        ,substr(designed_route_path,2,1) as designed_route2

        ,index(substr(act_route_path,1,1),substr(designed_route_path,1,1)) as substr1
        ,index(substr(act_route_path,2,1),substr(designed_route_path,2,1)) as substr2
    from g
)a
;
quit;

如果您发布数据,可以使代码更干净。

您可以使用
compress
对两个路由值进行反连接比较

data have;
  input route1 $8. route2 $8.; datalines;
ABCDEFGH CDEFGHI
ACEGI    BCDEFGHI
ABCD     EFGH
1234     1234
run;

proc sql;
  create table want as
  select route1, route2
  , case 
      when route1=route2 then 'Same route'
      else 
        'diff:' 
        || '-' || trim(compress(route1, route2))  /* chars in 1 not in 2 */
        || '+' || trim(compress(route2, route1))  /* chars in 2 not in 1 */
    end  as route_compare length=25
  from have;

当他们不匹配时,他们是像‘ABCDEFG’和‘ABCDEFGHIJ’那么不匹配的只是‘HIJ’,还是像‘ABCDEFG’和‘HIJKLMNO’那样根本不匹配?不清楚你想要什么,所以很难说。发布一个示例,说明数据的外观和输出内容。列表是否有分隔符?字符必须在相同的位置匹配吗?您是否想要一个结果,例如
-+
列表确实有一个delimeter(-)。我将尝试此代码并确定它是否有效。我从未尝试过这样做,所以不确定我到底在寻找什么代码。非常感谢。我也将尝试这段代码并报告。谢谢