BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jaheuk
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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.

proc sql noprint;
  
select quote(trim(name)) into :vars separated by ';'
  
from dictionary.columns where libname="SASHELP"    & memname="CLASS" order by varnum ;
  
quit;
%put NOTE: %superq(vars);

filename temp temp;*'c:\temp\test.txt' ;
data _null_;
  
file temp dlm=";" dsd lrecl=3000;
  
put %sysfunc(quote(%superq(vars)));
   do until (eof);
      set SASHELP.CLASS end=eof;
      put (_all_)(~);
      end;
  
stop;
  
run;
data _null_;
  
infile temp;
  
input;
  
put _infile_;
  
run;


12-16-2014 6-45-37 AM.png

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

data_null__
Jade | Level 19

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.

proc sql noprint;
  
select quote(trim(name)) into :vars separated by ';'
  
from dictionary.columns where libname="SASHELP"    & memname="CLASS" order by varnum ;
  
quit;
%put NOTE: %superq(vars);

filename temp temp;*'c:\temp\test.txt' ;
data _null_;
  
file temp dlm=";" dsd lrecl=3000;
  
put %sysfunc(quote(%superq(vars)));
   do until (eof);
      set SASHELP.CLASS end=eof;
      put (_all_)(~);
      end;
  
stop;
  
run;
data _null_;
  
infile temp;
  
input;
  
put _infile_;
  
run;


12-16-2014 6-45-37 AM.png
Ksharp
Super User

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2432 views
  • 1 like
  • 4 in conversation