Help using Base SAS procedures

Proc export

Reply
Frequent Contributor
Posts: 90

Proc export

Hi,

I need to export a dataset to the flat file , each field in each record is separated by a tilde and each record in each file is delimited by a right bracket.Below is my code,

PROC EXPORT DATA=Enrollment
OUTFILE= "C:\Documents and Settings\Desktop\Enroll.txt"
DBMS=DLM;
DELIMITER= '~';
RUN;

My question is whats the option need to use to get the special character "}" at the end of the each record.

Report needs to look like,

123~345~0~3.00~A12345}
234~567~1~4.89~C23456}

Thanks in Advance.
Frequent Contributor
Frequent Contributor
Posts: 94

Re: Proc export

I'm not aware of an option to do this directly, but you could take the code produced by Proc Export (it'll be in your log file), and use that directly.

You'll see where the delimiter is specified, and you can just add an extra put ( '(' ); after it outputs the other lines.
Frequent Contributor
Posts: 90

Re: Proc export

Hi DF,

I tried like this. If you want to use PROC EXPORT, the easiest way to get a } at the end of each record is to create a variable with ' }' as the value for each record. Then when you do the EXPORT, that variable will get written out at the end.

data Enrollment;
set Enrollment;
last = '}';
run;

PROC EXPORT DATA=Enrollment
OUTFILE= "C:\Documents and Settings\Desktop\Enroll.txt"
DBMS=DLM;
DELIMITER= '~';
RUN;

It works well. Is there any way to hide that 'column last' in the flat file ?

Thanks.
PROC Star
Posts: 7,492

Re: Proc export

Indirectly. After running your code, do a recall last submit (i.e., function key f4).

That will recall the datastep that was actually submitted. In it, early in the code, you'll see the statement that outputs the variable names (i.e., if _n_ eq 1, put, etc, etc.), with the last couple of lines in that section putting your tilde and bracket.

Simply delete the unwanted characters and run the datastep directly.

HTH,
Art
----------
> Hi DF,
>
> I tried like this. If you want to use PROC EXPORT,
> the easiest way to get a } at the end of each record
> is to create a variable with ' }' as the value for
> each record. Then when you do the EXPORT, that
> variable will get written out at the end.
>
> data Enrollment;
> set Enrollment;
> last = '}';
> run;
>
> PROC EXPORT DATA=Enrollment
> OUTFILE= "C:\Documents and
> Settings\Desktop\Enroll.txt"
> DBMS=DLM;
> DELIMITER= '~';
> RUN;
>
> It works well. Is there any way to hide that 'column
> last' in the flat file ?
>
> Thanks.
Super User
Posts: 10,046

Re: Proc export

[pre]
data _null_;
set sashelp.class;
file 'c:\temp\class.txt' delimiter='~';
put (_all_ ) (Smiley Happy +(-1) '}';
run;
[/pre]


Ksharp
Ask a Question
Discussion stats
  • 4 replies
  • 438 views
  • 0 likes
  • 4 in conversation