合并 SAS 数据集

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

Combining SAS datasets

问题

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

DATA Latest_data;
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 :

DATA Latest_data;
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将不存在的文件视为非错误。只需确保随后重新设置它。

示例:

1188  options nodsnferr;
1189  data want;
1190    set sashelp.class xy xyz ;
1191  run;

NOTE: 数据集WORK.WANT有19个观测值和5个变量。
NOTE: 数据语句已使用(总处理时间):
      实际时间           0.01秒
      CPU时间            0.01秒

1192  options dsnferr;
1193  data want;
1194    set sashelp.class xy xyz ;
ERROR: 文件WORK.XY.DATA不存在。
ERROR: 文件WORK.XYZ.DATA不存在。
1195  run;

NOTE: 由于错误,SAS系统停止处理此步骤。
WARNING: 数据集WORK.WANT可能不完整。当此步骤停止时,观测值为0,变量为5。
WARNING: 数据集WORK.WANT未被替换,因为此步骤被停止。
NOTE: 数据语句已使用(总处理时间):
      实际时间           0.00秒
      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:

1188  options nodsnferr;
1189  data want;
1190    set sashelp.class xy xyz ;
1191  run;

NOTE: The data set WORK.WANT has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


1192  options dsnferr;
1193  data want;
1194    set sashelp.class xy xyz ;
ERROR: File WORK.XY.DATA does not exist.
ERROR: File WORK.XYZ.DATA does not exist.
1195  run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete.  When this step was stopped there were 0 observations and 5 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      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.

DATA Latest_data;
    set %if(%sysfunc(exist(new_table&yday))) %then %do;
            new_table&yday.
        %end;

        %if(%sysfunc(exist(new_table&Bfryday.))) %then %do;
            new_table&Bfryday.
        %end;

        %if(%sysfunc(exist(append_new&yday.))) %then %do;
            append_new&yday.
        %end;

        %if(%sysfunc(exist(append_new&Bfryday.))) %then %do;
            append_new&Bfryday.
        %end;
    ;
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:

确定