3

I am trying to print out a delimited file, without having to specify all of the columns. I can get close, but the numeric columns are always quoted:

DATA _NULL_;
  SET SASHELP.CARS (obs = 5 keep = Make Model EngineSize);
  FILE "foo.csv" DSD DLM=",";
  PUT (_all_) (~);
RUN;

foo.csv

"Acura","MDX","3.5"
"Acura","RSX Type S 2dr","2"
"Acura","TSX 4dr","2.4"
"Acura","TL 4dr","3.2"
"Acura","3.5 RL 4dr","3.5"

How can I achieve either:

"Acura","MDX",3.5
"Acura","RSX Type S 2dr",2
"Acura","TSX 4dr",2.4
"Acura","TL 4dr",3.2
"Acura","3.5 RL 4dr",3.5

or:

Acura,MDX,3.5
Acura,RSX Type S 2dr,2
Acura,TSX 4dr,2.4
Acura,TL 4dr,3.2
Acura,3.5 RL 4dr,3.5
mlegge
  • 6,763
  • 3
  • 40
  • 67
  • See this closely related [question](http://stackoverflow.com/questions/31869021/file-statement-in-data-step-to-export-comma-delimited-text-file?lq=1) . I'm of mixed feelings on if this is a dup or not, so if others think it is i'll close it - otherwise not. – Joe Dec 02 '15 at 21:26

1 Answers1

3

~ asks for quoting. So, you're getting quoting.

You can use & instead:

DATA _NULL_;
  SET SASHELP.CARS (obs = 5 keep = Make Model EngineSize);
  FILE "c:\temp\foo.csv" DSD DLM=",";
  PUT (_all_) (&);
RUN;

& has effectively no impact on the data (we've had a question about it once upon a time, I don't recall the ultimate answer, but basically it seems to mostly be used for this specific purpose, even though that's not its purpose).

Joe
  • 62,789
  • 6
  • 49
  • 67
  • `:` also works fine, by the way. There are probably some other options also. – Joe Dec 02 '15 at 21:11
  • Thanks @Joe! Do you have a link for these references? I could not find it after crawling around in the knowledge base for a while – mlegge Dec 02 '15 at 21:12
  • 1
    There's not really a reference for how you do exactly what you're asking. What you're basically doing is cheating. The purpose of the `put (a) (b)` functionality is to apply a common format/etc. to all variables in the variable list (a). Normally you could just write your variable list out; but because `put _all_;` has a special functionality, you have to override it by forcing it into this other method. What you put in the second pair of parens doesn't matter: just something that's not harmful, but allows SAS to think you're applying something to all of the variables in `_all_`. – Joe Dec 02 '15 at 21:23
  • You can use `(+0)` for the format list. That always seems clear to me that it will do nothing since it just moves the pointer zero spaces. – Tom Dec 03 '15 at 02:22