BookmarkSubscribeRSS Feed
raveena
Obsidian | Level 7
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.
4 REPLIES 4
DF
Fluorite | Level 6 DF
Fluorite | Level 6
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.
raveena
Obsidian | Level 7
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.
art297
Opal | Level 21
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.
Ksharp
Super User
[pre]
data _null_;
set sashelp.class;
file 'c:\temp\class.txt' delimiter='~';
put (_all_ ) (:) +(-1) '}';
run;
[/pre]


Ksharp

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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