Sas proc sql 中的左连接

问题描述 投票:0回答:1

我有许多这样组织的数据库

a number of job position with different incomes

year by year the same id can have more or less positions of the year before

如果我用这段代码进行左连接

proc sql;
     create table campione_15_&annodue. as
         select a.*, 
            b.ANNO_RIFERIMENTO as ANNO_RIFERIMENTO_&annodue., 
               b.CODENTE as CODENTE_&annodue.,        
                   b.RETRIBUZIONE as RETRIBUZIONE_&annodue.
             from Bv_inps_casell_posatt_&anno. as a
                    left join damm.Bv_inps_casell_posatt_&annodue. as b
                         on a.codice_individuo = b.codice_individuo;
quit;

我有这个结果

a number of records that is a product of the first for the second db

虽然我不希望数据集爆炸

desired option

感谢任何愿意提供帮助的人

sql sas left-join
1个回答
0
投票

很难说出你在问什么。但从您的代码示例来看,您似乎有一系列数据集,其中仅在数据集的名称中编码了年份。如果是这样,那么您可以使用普通的 SAS 代码(忘记尝试使用 SQL 使您的任务变得更加困难)来组合数据集并创建 YEAR 变量。

假设您有 2015 年到 2020 年的数据,那么您可以运行此数据步骤并利用 SET 语句的 INDSNAME= 选项来访问当前观测值来源的数据集的名称。

data want;
  set  Bv_inps_casell_posatt_2015 -  Bv_inps_casell_posatt_2020 indsname=dsname;
  year = input(scan(dsname,-1,'_'),4.);
run;
© www.soinside.com 2019 - 2024. All rights reserved.