Dear all,
I finally discovered that using a tilde put quotes around the values.
Perfect!!
Now I still what quotes around the headers.
I can use the quote function in the query quote(trim(name)) . . and yes quotes are added but the PUT statement still
fails in the data _null_ step.
Suggestions???
proc sql noprint;
select trim(name) into :vars separated by ';'
from dictionary.columns
where libname="SASHELP" & memname="CLASS"
order by varnum ;
quit;
filename temp 'c:\temp\test.txt' ;
data _null_;
file temp dlm=";" dsd lrecl=3000;
put "&vars." ;
do until (eof);
set SASHELP.CLASS end=eof;
put (_all_)(~);
end;
stop;
run;
GreetZ,
Herman
You need to make the syntax correct by doubling the double quotes inside the quoted string in the PUT statement. Use the QUOTE function again on VARS.
Well, I am sure there is a better way, however you can generate the necessary code rather than using a macro variable, something like:
filename temp 's:\temp\rob\test.txt' ;
data temp;
set sashelp.vcolumn (where=(libname="SASHELP" and memname="CLASS")) end=last;
length lst_list $2000.;
retain lst_list;
if _n_=1 then lst_list='"'||strip(name)||'";';
else lst_list=strip(lst_list)||'"'||strip(name)||'";';
if last then do;
call execute('data _null_; file temp dlm=";" dsd lrecl=3000; set sashelp.class;');
call execute(" put '"||strip(lst_list)||"';");
call execute('; put (_all_)(~); run;');
end;
run;
You need to make the syntax correct by doubling the double quotes inside the quoted string in the PUT statement. Use the QUOTE function again on VARS.
Why not use ods csv ?
ods csvall file='c:\temp\x.csv' options(doc="help" Delimiter=';' Quoted_columns="123456789"); title ' '; proc print data=sashelp.class noobs;run; ods csvall close;
Xia Keshan
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.