使用循环或宏合并sas中的多个表 [英] Merge multiple tables in sas using loop or macro

查看:18
本文介绍了使用循环或宏合并sas中的多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经循环生成了 Forecast_2013 到 2022 的表,然后将所有数据集合并到 1 个表中.但是现在我想在一个循环中合并数据集,无论年份如何,明年将是 2023 年或 2024 年......我不想手动设置 Forecast_2023;设置 Forecast_2024.如何使用宏放入循环?

I have generated the tables of Forecast_2013 to 2022 in a loop and then merged all datasets in to 1 Table. But now I want to do merge the datasets in a loop with irrespective of years, The next year will be 2023 or 2024...I dont want to do mannually to set Forecast_2023;set forecast_2024. How can I put in to loop using macro?

Data P_OT.FORECAST(DROP=td qq AGE1 AGE2 AGE3 AGE4  AGEBANDFCST020 AGEBANDFCST030 AGEBANDFCST035P
     HSI1_2012 HSI1_2013 HSI1_2014 HSI1_2015 HSI1_2016 HSI1_2017 HSI1_2018 HSI1_2019 HSI1_2020  HSI1_2021 HSI1_2022);

set FORECAST_2013;set FORECAST_2014;set FORECAST_2015;set FORECAST_2016;
set FORECAST_2017;set FORECAST_2018;set FORECAST_2019;set FORECAST_2020;
set FORECAST_2021;set FORECAST_2022;
run;

推荐答案

Scott 发布的替代方案是:

An alternative to what Scott posted would be:

*Assign library to folder where FORECAST_ files are located;
libname NAME 'C:Path to Folder';

*Data step to stack files;
Data P_OT.FORECAST(DROP=td qq AGE1 AGE2 AGE3 AGE4  AGEBANDFCST020 
    AGEBANDFCST030 AGEBANDFCST035P HSI1_:);
    set NAME.FORECAST_:;
run;

这应该与 Scott 使用名称前缀列表而不是使用 SQL 生成要合并的数据集列表和要删除的变量的结果相同.

This should give the same results as what Scott posted using name prefix lists instead of using SQL to produce lists of datasets to be merged and variables to be dropped.

上面的代码将堆叠 libname 库中以FORECAST_"开头的所有数据集.它还将删除创建的数据集中以HSI1_"开头的所有变量.

The code above will stack all datasets in the libname library that start with "FORECAST_". It will also drop all variables in the created dataset that begin with "HSI1_".

这篇关于使用循环或宏合并sas中的多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆