SAS-在while循环期间如何将2个数值连接到变量名上

时间:2019-03-26 16:01:27

标签: string sas append concat numeric

我试图通过编写循环来绕过语句负载来改善一些SAS代码。语句代码块的示例如下:

    package junit;

import io.restassured.RestAssured;
import net.serenitybdd.junit.runners.SerenityRunner;
import net.serenitybdd.rest.SerenityRest;
import net.thucydides.core.annotations.Title;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;


@RunWith(SerenityRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class getMaterialHVT {


        @BeforeClass
        public static void init(){
            RestAssured.baseURI="https://dt.pulsenow.co.uk";

        }


        @Title("Get all information for Hazard and Risks")
        @Test
        public void hazardAndRisks() {
            SerenityRest.given()
                    .when()
                    .get("/assettracking/material/hvt")
                    .then()
                    .log()
                    .all()
                    .statusCode(200);
        }

}

这样持续14行...

因此,我认为我可以做一个while循环来遍历前9个数字,并在其前面插入/连接一个0,而不是这些语句。 不幸的是零是必需的。

if rpq_stage_date_01 ne . then stage_date_01 = rpq_stage_date_01; 
if gps_stage_date_01 ne . then stage_date_01 = gps_stage_date_01;
if ldr_stage_date_01 ne . then stage_date_01 = ldr_stage_date_01; 

if rpq_stage_date_02 ne . then stage_date_02 = rpq_stage_date_02; 
if gps_stage_date_02 ne . then stage_date_02 = gps_stage_date_02;
if ldr_stage_date_02 ne . then stage_date_02 = ldr_stage_date_02;

我尝试了一些不同的事情,例如cat,catx,'||'操作员。在python中,这实现起来会很有趣,但是事实证明,SAS对于我的绿色SAS自我来说没有那么灵活。有人甚至不再使用SAS吗?我很感兴趣!

任何帮助将不胜感激!干杯。

1 个答案:

答案 0 :(得分:0)

此代码

if rpq_stage_date_01 ne . then stage_date_01 = rpq_stage_date_01; 
if gps_stage_date_01 ne . then stage_date_01 = gps_stage_date_01;
if ldr_stage_date_01 ne . then stage_date_01 = ldr_stage_date_01; 

可以替换为

stage_date_01 = coalesce(ldr_stage_date_01,gps_stage_date_01,rpq_stage_date_01);

您可以定义数组以对数组进行一次处理。

Array RPQ[*] RPT_STAGE_DATE:;
array gps[*] gps_stage_date:;
array ldr[*] ldr_stage_date:;
array stg[*] stage_date_01-stage_date_10;
do I = 1 to dim(stg);
   stg[i] = coalesce(ldr[I],gps[I],rpq[I]);
   end;