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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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