BookmarkSubscribeRSS Feed
shuchidxt_gmail_com
Obsidian | Level 7

Hi,

 

I am trying to export a dataset into text file. when I am doing this...my text in the data look like as

 

No wire activity was identified during an extended search from July-September 2018. BAU All Trans report identified minimal activity; of note was a debit for $122K stating "OFAC/Funds moved to Omnibus". UAR# 4134354

 

but when it is writing to the text file it convert it to below adding quotes to the text as bold highligted

 

 


"No wire activity was identified during an extended search from July-September 2018.  BAU All Trans report  identified minimal activity; of note was a debit for $122K stating ""OFAC/Funds moved to Omnibus"". UAR# 4134354

8 REPLIES 8
Tom
Super User Tom
Super User

How did you "export" to the text file?

If tried to create a delimited file then SAS used the DSD option to allow for proper protection of delimiters. So if any data item contains the delimiter then the value is enclosed in quotes.  But that means that it also need to protect values that contain the quote character itself to avoid confusion for values like:

"hello"
shuchidxt_gmail_com
Obsidian | Level 7

I use as below

 

proc export data=out.alerts_export outfile="&outbound_folder_path/%lowcase(&case_type_cd.)_alerts_export_&tbl..txt" replace dbms=dlm;
  delimiter='|';
 quit;

 

pipe delimited file

ScottBass
Rhodochrosite | Level 12

See https://github.com/scottbass/SAS/blob/master/Macro/export.sas, perhaps it will help? 

 

You'll also need to copy https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas.

 

The concepts are copied from https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-use-labels-in-proc-export-or-create-tab..., so all the smarts of the macro are due to @data_null__

 

I just put some macro wrapper code around his code.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
shuchidxt_gmail_com
Obsidian | Level 7
So what is the solution?
Tom
Super User Tom
Super User

@shuchidxt_gmail_com wrote:
So what is the solution?

What is the problem?  That is how delimited files are SUPPOSED to be made.

What are you reading it with that is not properly removing the added quoting?

shuchidxt_gmail_com
Obsidian | Level 7

Yes, we send this file to downstream application with 200 character long. Right now the length is 203 because of the extra quotes added.

their job will fail if we send them data more than 200 character long string.

Tom
Super User Tom
Super User

What application are you using that is misreading the file so that it thinks the value is 203 characters long?

 

For example if the downstream process is Amazon Redshift COPY command then make sure to include the CSV option so that it handles the quotes properly.

Tom
Super User Tom
Super User

If you MUST create a file that is using a non standard format then you will probably need to create the file using a data step.

But you will then have to make your own checks for how to handle values with embedded delimiters and how to handle missing values.

 

If you know that your data does not have either of these issues then your data step could be as simple as:

data _null_;
   set sashelp.class ;
   file log dlm='|';
   put (_all_) (:);
run;

Replace the LOG keyword with the quoted physical name of the file you want to create. Replace SASHELP.CLASS with the name of your file.

If you want the variable names added as a header row then you could just add a little more code.

filename csv temp;
proc transpose data=sashelp.class(obs=0) out=names; run;
data _null_;
  file csv dlm='|';
  set names end=eof;
  put _name_ @;
  if eof then put;
run;
data _null_;
  set sashelp.class ;
  file csv mod dlm='|';
  put (_all_) (:);
run;

Again replace the TEMP keyword with the quoted physical name of the file you want to create.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 879 views
  • 0 likes
  • 3 in conversation