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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.