gpt4 book ai didi

SAS:PROC EXPORT中的限制变量

转载 作者:行者123 更新时间:2023-12-04 18:12:03 26 4
gpt4 key购买 nike

我有一个PROC EXPORT问题,我想知道您是否可以回答。

我有一个SAS数据集,其中包含800多个变量和超过200K的观测值,并且我正在尝试将变量的子集导出到CSV文件(即,我需要所有记录;我只是不想要所有800+个变量)。我总是可以仅在需要的字段上创建一个临时数据集“KEEP”,然后在该临时数据集上运行EXPORT,但是由于我拥有大量记录,因此我试图避免执行附加步骤。

为了说明这一点,请考虑具有三个名为x,y和z的变量的数据集。但是,我希望通过PROC EXPORT生成的文本文件仅包含x和y。我在下面的解决方案中的尝试不太奏效。

SAS代码

当我运行以下代码时,我并没有得到我真正需要的东西。如果运行此代码并查看生成的文本文件,则在每行的末尾都有一个逗号,并且标题仍然包含数据集中的所有变量。另外,我在日志中收到一些我不应该收到的消息。

data ds1;
do x = 1 to 100;
y = x * x;
z = x * x * x;
output;
end;
run;

proc export data=ds1(keep=x y)
file='c:\test.csv'
dbms=csv
replace;
quit;

这是生成的文本文件的前几行(“C:\test.csv”)
x,y,z
1,1,
2,4,
3,9,
4,16,

SAS日志
9343  proc export data=ds1(keep=x y)
9344 file='c:\test.csv'
9345 dbms=csv
9346 replace;
9347 quit;

9348 /**********************************************************************
9349 * PRODUCT: SAS
9350 * VERSION: 9.2
9351 * CREATOR: External File Interface
9352 * DATE: 30JUL12
9353 * DESC: Generated SAS Datastep Code
9354 * TEMPLATE SOURCE: (None Specified.)
9355 ***********************************************************************/
9356 data _null_;
9357 %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
9358 %let _EFIREC_ = 0; /* clear export record count macro variable */
9359 file 'c:\test.csv' delimiter=',' DSD DROPOVER lrecl=32767;
9360 if _n_ = 1 then /* write column names or labels */
9361 do;
9362 put
9363 "x"
9364 ','
9365 "y"
9366 ','
9367 "z"
9368 ;
9369 end;
9370 set DS1(keep=x y) end=EFIEOD;
9371 format x best12. ;
9372 format y best12. ;
9373 format z best12. ;
9374 do;
9375 EFIOUT + 1;
9376 put x @;
9377 put y @;
9378 put z ;
9379 ;
9380 end;
9381 if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
9382 if EFIEOD then call symputx('_EFIREC_',EFIOUT);
9383 run;

NOTE: Variable z is uninitialized.
NOTE: The file 'c:\test.csv' is:
Filename=c:\test.csv,
RECFM=V,LRECL=32767,File Size (bytes)=0,
Last Modified=30Jul2012:12:05:02,
Create Time=30Jul2012:12:05:02

NOTE: 101 records were written to the file 'c:\test.csv'.
The minimum record length was 4.
The maximum record length was 10.
NOTE: There were 100 observations read from the data set WORK.DS1.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.01 seconds


100 records created in c:\test.csv from DS1.


NOTE: "c:\test.csv" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):
real time 0.12 seconds
cpu time 0.06 seconds

有什么想法可以解决这个问题吗?我在Windows 7上运行SAS 9.2。

任何帮助,将不胜感激。谢谢。
  • Karthik
  • 最佳答案

    根据Itzy对我的问题的评论,这是答案,这正是我所需要的。

    proc sql;
    create view vw_ds1 as
    select x, y from ds1;
    quit;

    proc export data=vw_ds1
    file='c:\test.csv'
    dbms=csv
    replace;
    quit;

    谢谢您的帮助!

    关于SAS:PROC EXPORT中的限制变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11727469/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com