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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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