Hi All..
I am exporting a dataset into CSV format with using following code..
%macro exportdsPR;
proc contents data=sasuser.admit out=rcount(keep=NOBS NAME) details noprint;
run;
%let empty=YES;
%let var=;
data null;
set rcount(obs=1);
if nobs ge 1 then call symput('empty', 'NO');
run;
%if &empty = NO %then %do;
data null ;
set sasuser.admit end=EFIEOD;
%let EFIERR = 0;
%let EFIREC = 0;
file "C:\Documents and Settings\sanjeev.k\Desktop\New Folder\test.csv" delimiter=',' DSD DROPOVER lrecl=32767;
EFIOUT + 1;
put id $ @;
put name $ @;
put sex $ @ ;
put age $ @ ;
put date $ @ ;
put height $ @;
put weight $ @ ;
put actlevel $ @;
put fee $ ;
if ERROR then call symputx('_EFIERR_',1);
if EFIEOD then call symputx('_EFIREC_',EFIOUT);
run;
%end;
%mend exportdsPR;
With this code ,CSV file exporting successfully without column names.
Is it possible to get Column Names in the exported CSV file??
Could you please provide any solution for this..
Thanks in Advance..
Regrads
Sanjeev.K
Please go through below, this may help
https://communities.sas.com/thread/31487?start=0&tstart=0
Thanks and Regards,
Yaswanth J.
Hi Sanjeev,
How about the following:
data _null_;
call symputx('_EFIREC_',nobs);
stop;
set sashelp.class nobs=nobs;
run;
%macro writecsv;
%if &_EFIREC_ %then
%do;
%ds2csv(data =sashelp.class
,runmode=b
,csvfile=C:\Documents and Settings\sanjeev.k\Desktop\New Folder\test.csv
,var =name sex age /* omit this line if you want all variables */
);
%end;
%mend writecsv;
%writecsv;
Regards,
Amir.
Message was edited by: Amir Malik - formatting.
Hi Amir..
Thanks for your solution..
but i can not continue with your solution,because i don't want to disturb the code which i have mentioned in my question as some conditions mentions in that code(IF dataset was empty Export file should not be created).
Can you please do work with my code and if possible provide the solution..
Thanks &Regards..
Sanjeev.K
Hi Sanjeev,
The condition:
%if &_EFIREC_ %then
in the code means the csv file is only produced if there are any records.
Regards,
Amir.
Hi Sanjeev,
Further, the link referred to by Yaswanth has a simple solution if you want to change your code as little as possible.
Regards,
Amir.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.