BookmarkSubscribeRSS Feed
qwererty
Calcite | Level 5

Hi

I am using a file writer transformation in DI studio 4.4 to write a dataset to a text file.  I am faced with two problems, firstly every fiels is enclosed in quotation marks.  I believe this is because within some of the field I have non alphanumeric characters like "-".  The second issue I have is that there is a field with numeric characters.  They look fine in the dataset but when exported they are exported as 2.99e6 (or something similar) this ends up being 290000.  Most importantly how can I maintain the number in the field? secondly how can I export without quotation marks.

I have managed to export without quotation marks by editing the code to remove all references to "quote" (see below) although I would rather use a standard transformation if possibkle than modify one, VAR 5 is the numeric field.  I have highlighted the fields I remove/ modify to get output without quotes.


%let SYSLAST = work.W4VOE3O;

data _null_;
   set &SYSLAST;
      attrib VAR1 length = $3;

     attrib VAR2 length = $3;

     attrib VAR3 length = $3;

     attrib VAR5 length = 8;
            quote='"';
      file "$DISC_FTP/info_today_date1._&tf_hour.00.txt" LRECL=32760 dlm='|';
     
         put
            quote +(-1)VAR1  +(-1) quote

               quote +(-1)VAR2  +(-1) quote

               quote +(-1)VAR3  +(-1) quote

               quote +(-1)VAR4  +(-1) quote

               quote +(-1)VAR5  +(-1) quote
                        ;

run;

Thanks

4 REPLIES 4
LinusH
Tourmaline | Level 20

About the numerical variables, any specified format should be honored.

The quotes seems a bit more frustrating :smileyconfused:

Your option would be to use User written body ( as you probably already tested), but that's not recommended.

An option would be to create a User Written File Writer transformation. With this, you will get the data types and format of all output variables in your target file as macro variables, so you could make the code dynamic.

In my opinion, both File reader and Writer transformations seems like an early hack, and should be candidates for enhancements.

Data never sleeps
JanB
Calcite | Level 5

"You must select "Treat consecutive delimiters as a single delimiter" in the external file properties (File Parameters tab) to prevent the double quotation marks from being included in the data."

And it worked to me.

jakarman
Barite | Level 11

Why not use: SAS(R) 9.4 Formats and Informats: Reference The $quote. format? It does the thing you described. Doubling somet thing as usual conention incuded. 

---->-- ja karman --<-----
jakarman
Barite | Level 11

The other mentioned issue with numerics is known as precision. Apply a correct format and rounding is included. https://support.sas.com/techsup/technote/ts654.pdf 

---->-- ja karman --<-----

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 3421 views
  • 1 like
  • 4 in conversation