LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 24 Dec 2004 08:31:02 -0500
Reply-To:   Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Subject:   Re: Losing data when writing a text file out
Comments:   To: david Fickbohm <DavidF@HOMEGAIN.COM>

Merry Christmas David many answers have already got you on the road to alternative solutions. One option no one seems to have indicated is the DSD option of the file statement. It is practically designed for generating files like yours! DSD inserts delimiters between each variable (but, unfortunately, not quoted constants). Adding the ~ to the put statement guarantees the v8 defect (not masking unbalanced " marks in values that don't also have a delimiter embedded), won't affect your output; Suppose you have a list of the columns you want in your output file, like: %let cols_wanted = USERID EMAIL LEAD1TYPE LEAD1CITY LEAD2TYPE LEAD2CITY LEAD3TYPE LEAD3CITY USERNAME ZIPS8 DAILYLEADS LEAD1EST LEAD2EST LEAD3EST FIRSTNAME ; %let delimiter = %str(|) ; %let headings = %sysfunc( translate( &cols_wanted, &delimiter, %str( ) ));

data _null_; file "T:\DM\~\USERS\DAVEF\AGENT_LEADS\OUTPUT\LEADS3_122304.TXT" dsd dlm = &delimiter lrecl= 3000 ;

if _n_ = 1 then put "&headings" ;

set FINAL04 ; put ( &cols_wanted )(~) ; run;

Of course, you can replace these macro variables by the appropriate lists or values.

Seasons greetings Peter Crawford Crawford Software Consultancy Limited UK

On Thu, 23 Dec 2004 09:41:07 -0800, David Fickbohm <DavidF@HOMEGAIN.COM> wrote:

>People, >I am trying to write out a text file. The text file will be read into an >excel spreadsheet. I am using "|" between each variable. I am having two >problems. >1 - The first line of data currently does not get written out (I think I >need to extend or add another put statement below the first put and have >tried all kinds of combinations and have gotten nowhere but frustrated.) >2 - Each line starts off with a "|". Excel treats this as a blank variable >and when the text file is written to excel the first column shows in column >B. > >Here is the current code: > >DATA _NULL_; > SET FINAL04; >file "T:\DM\~\USERS\DAVEF\AGENT_LEADS\OUTPUT\LEADS3_122304.TXT" noprint >notitles; >IF _N_ = 1 THEN >PUT >'userid|email|lead1type|lead1city|lead2type|lead2city|lead3type|lead3city| us >ername > |zips8|dailyleads|lead1est|lead2est|lead3est|first name'; >ELSE >PUT (USERID EMAIL LEAD1TYPE LEAD1CITY LEAD2TYPE LEAD2CITY LEAD3TYPE >LEAD3CITY USERNAME > ZIPS8 DAILYLEADS LEAD1EST LEAD2EST LEAD3EST FIRSTNAME)(+1'|'); >RUN; > >Here is some sample data >userid email lead1type lead1city >lead2type lead2city lead3type lead3city username zips8 dailyleads lead1est >lead2est lead3est firstname >1111 df@11.net buyer sf seller >sa buyer sr abc yes 3 >12345 12345 12345 dave >5556 lexington_office@hunneman.com Buyer Waltham . . . >. marcia stille off 3 $600,000 $500,000 Marcia >5564 marykay1@mindspring.com Buyer Durham . . . . .marykay >pendergraph .on .1 .$175,000 . . Mary Kay > > >Here is the current output >userid|email|lead1type|lead1city|lead2type|lead2city|lead3type|lead3city|u se >rname |zips8|dailyleads|lead1est|lead2est|lead3est|first name > |5556 |lexington_office@hunneman.com |Buyer |Waltham | | | | >|marcia stille |off |1 |$600,000 |. |. |Marcia > |5564 |marykay1@mindspring.com |Buyer |Durham | | | | |marykay >pendergraph |on |1 |$175,000 |. |. |Mary Kay > >I need >userid|email|lead1type|lead1city|lead2type|lead2city|lead3type|lead3city|u se >rname |zips8|dailyleads|lead1est|lead2est|lead3est|first name > 1111 |abc@yahoo.com|buyer|somewhere|seller|another|seller|thirdcity|joe >blow|yes|3|12345|12345|12345|dave > 5556 |lexington_office@hunneman.com |Buyer |Waltham | | | | >|marcia stille |off |1 |$600,000 |. |. |Marcia > 5564 |marykay1@mindspring.com |Buyer |Durham | | | | |marykay >pendergraph |on |1 |$175,000 |. |. |Mary Kay > >All help, thoughts, ideas, greatly appreciated. >Thanks >Dave


Back to: Top of message | Previous page | Main SAS-L page