合并 SAS 数据集

huangapple go评论99阅读模式
英文:

Combining SAS datasets

问题

我必须通过从以下文件之一获取数据来创建一个SAS数据集:

  1. DATA Latest_data;
  2. SET new_table&yday. new_table&Bfryday. append_new&yday. append_new&Bfryday.; RUN;

因此,在SET语句中的4个文件中,只有一个可能存在。因此,当我尝试创建Latest_data时,会出现错误,因为其余3个数据集为空。如何解决这个问题或可以使用什么其他方法。&yday的值类似于30MAY2023,&Bfryday的值类似于29MAY2023。

英文:

I have to create a SAS dataset by taking data from either of the below files :

  1. DATA Latest_data;
  2. SET new_table&yday. new_table&Bfryday. append_new&yday. append_new&Bfryday.; RUN;

So here among the 4 files present in the SET statement only one of might will exists. So when I am trying to create the Latest_data it throws the an error since the rest 3 datasets are empty. How can I resolve this or what other method can be used.
&yday has a value like 30MAY2023 and &Bfryday has a value like 29MAY2023

答案1

得分: 3

你可以通过设置NODSNFERR系统选项,告诉SAS将不存在的文件视为非错误。只需确保随后重新设置它。

示例:

  1. 1188 options nodsnferr;
  2. 1189 data want;
  3. 1190 set sashelp.class xy xyz ;
  4. 1191 run;
  5. NOTE: 数据集WORK.WANT19个观测值和5个变量。
  6. NOTE: 数据语句已使用(总处理时间):
  7. 实际时间 0.01
  8. CPU时间 0.01
  9. 1192 options dsnferr;
  10. 1193 data want;
  11. 1194 set sashelp.class xy xyz ;
  12. ERROR: 文件WORK.XY.DATA不存在。
  13. ERROR: 文件WORK.XYZ.DATA不存在。
  14. 1195 run;
  15. NOTE: 由于错误,SAS系统停止处理此步骤。
  16. WARNING: 数据集WORK.WANT可能不完整。当此步骤停止时,观测值为0,变量为5
  17. WARNING: 数据集WORK.WANT未被替换,因为此步骤被停止。
  18. NOTE: 数据语句已使用(总处理时间):
  19. 实际时间 0.00
  20. CPU时间 0.00
英文:

You could just tell SAS to treat a non-existent file as NOT an error by setting the NODSNFERR system option. Just make sure to set it on again.

Example:

  1. 1188 options nodsnferr;
  2. 1189 data want;
  3. 1190 set sashelp.class xy xyz ;
  4. 1191 run;
  5. NOTE: The data set WORK.WANT has 19 observations and 5 variables.
  6. NOTE: DATA statement used (Total process time):
  7. real time 0.01 seconds
  8. cpu time 0.01 seconds
  9. 1192 options dsnferr;
  10. 1193 data want;
  11. 1194 set sashelp.class xy xyz ;
  12. ERROR: File WORK.XY.DATA does not exist.
  13. ERROR: File WORK.XYZ.DATA does not exist.
  14. 1195 run;
  15. NOTE: The SAS System stopped processing this step because of errors.
  16. WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0 observations and 5 variables.
  17. WARNING: Data set WORK.WANT was not replaced because this step was stopped.
  18. NOTE: DATA statement used (Total process time):
  19. real time 0.00 seconds
  20. cpu time 0.00 seconds

答案2

得分: 2

这是一个很好的使用条件宏函数来检查每个数据集是否存在的用例。如果数据集存在,那么表将被添加到set语句中。否则,不会添加。

英文:

This is a good use case of using a conditional macro function to check if each dataset exists. If the dataset exists, then the table will be added to the set statement. Otherwise, it will not.

  1. DATA Latest_data;
  2. set %if(%sysfunc(exist(new_table&yday))) %then %do;
  3. new_table&yday.
  4. %end;
  5. %if(%sysfunc(exist(new_table&Bfryday.))) %then %do;
  6. new_table&Bfryday.
  7. %end;
  8. %if(%sysfunc(exist(append_new&yday.))) %then %do;
  9. append_new&yday.
  10. %end;
  11. %if(%sysfunc(exist(append_new&Bfryday.))) %then %do;
  12. append_new&Bfryday.
  13. %end;
  14. ;
  15. run;

huangapple
  • 本文由 发表于 2023年6月1日 00:07:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76375432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定