dataset=_last_ , /* Dataset to write */ |
filename=print , /* File to write to */ |
dlmr= "," , /* Delimiter between values */ |
qtes= "no" , /* Should SAS quote all character variables? */ |
header= "no" , /* Do you want a header line w/ column names? */ |
label= "no" /* Should labels be used instead of var names in header? */ |
proc contents data=&dataset out=___out_; |
/* Return to orig order */ |
/* Build list of variable names */ |
call symput( "name" !!left(put(_n_,3.)),name); |
call symput( "type" !!left(put(_n_,3.)),type); |
/* Use var name when label not present */ |
if label= " " then label=name; |
call symput( "lbl" !!left(put(_n_,3.)),label); |
if _n_=1 then call symput( "numvars" , trim(left(put(count, best.)))); |
%if &qtes= "yes" %then %let temp= |
%if &header= "yes" %then %do; |
/* Conditionally add column names */ |
put %if &label= "yes" %then %do; |
&temp "%trim(%bquote(&&lbl&i)) " +(-1) &temp &dlmr |
&temp "%trim(%bquote(&&lbl&numvars)) " &temp; |
&temp "%trim(&&name&i) " +(-1) &temp &dlmr |
&temp "%trim(&&name&numvars) " &temp ; |
/* Build PUT stmt to write values */ |
%do i = 1 %to &numvars -1; |
%if &&type&i ne 1 and &qtes= "yes" %then %do; |
%if &&type&i ne 1 and &qtes= "yes" %then %do; |
input id name :$20. amount ; |
label id= "Customer ID Number" ; |
/* If LRECL= required because of records longer the 256, specify here */ |
filename myfile "~/tmp/rawdata" lrecl=256; |
/* Invoke macro to write to a file, include proper parameters for your case. Make sure that the variables are in the order you want and have the desired formats. */ |
filename=myfile, /* FILEREF or DDNAME of the file */ |
There is one another simple method below but does not give that many options as the macro above... |
%macro delimitfile(dsn,dlm,fileref); |
put (_all_) (:); /* The colon here is dummy and has no effect */ |
filename out "c:\out1.csv" ; |
%delimitfile(sashelp.class, "|" ,out); |
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.