BookmarkSubscribeRSS Feed
4john
Calcite | Level 5
I have a dataset with sixty columns and 300 observations.I would like to create a tab delimited file with out the column variables in the first row.
I used below code.But its creating a tab space at the beginning of the first column.Please suggest me a way to create a tab delimited without the variable names in the first row.

data _null_;
file "&fileloc/&outfile" lrecl=32760;
set work.report;
put (_all_)('09'x);
run;

Thanks in advance.
6 REPLIES 6
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Investigate the DLM= keyword (and also DSD) on the FILE for changing this behavior.

Scott Barry
SBBWorks, Inc.
garybald
Calcite | Level 5
Try adding
DLM='09'x DSD
to your file statement

change your put statement to
put (_all_) ($);
4john
Calcite | Level 5
Thanks Gary.It worked.
It would be very helpful if you can give a brief explanation of how $ symbol next to put statement fixed this issue.

Thanks in advance.
garybald
Calcite | Level 5
I was experimenting based on this post I found in the knowledge base http://support.sas.com/kb/24/843.html
and got an error message that SAS was expecting a quoted string, $, &, /, //, :, =, ?, ~ (I think that's everything.)
When I tried the $, I got the result I wanted. I tried the others too and some gave me the same results as the $ while others like / inserted a carriage return. I'm not sure exactly what's going on, but it works, so I decided to post it.
Cynthia_sas
SAS Super FREQ
Hi:
Some comments...when you use PUT (_ALL_) you are tellling SAS to write ALL of the variables from the PDV (Program Data Vector) to the output file specified on the FILE statement. When you use a PUT like this, what you can (and should) always specify is the format to use to write the variables. The ($) tells SAS to use a character format for EVERYTHING that's being written.

In addition, the DLM= option and the DSD options on the FILE statement tell SAS to use the tab character (09'x) as the separator/delimiter and the DSD option tells SAS to put quotes around variable values which contain spaces and special characters, as described here:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000171874.htm

So in your case, the original PUT statement was never going to work:
[pre]
put (_all_)('09'x);
[/pre]

because ('09'x) is NOT a format -- it is what you wanted to use as a delimiter and it needed to be specified in the DLM= option. With just PUT (_ALL_) and NO format list, you would have gotten this error:
[pre]
1658 put (_all_);
-
79
76
ERROR 79-322: Expecting a (.

ERROR 76-322: Syntax error, statement will be ignored.

[/pre]


So the ($) made the PUT statement happy with a format to use for every variable in the PDV. And the DLM= option told SAS to use the tab as the separator.

cynthia
4john
Calcite | Level 5
Thanks for the explanation Cynthia and Gary.

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
  • 6 replies
  • 2777 views
  • 0 likes
  • 4 in conversation