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 (April 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 10 Apr 2008 09:08:54 -0400
Reply-To:     Nathaniel.Wooding@DOM.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Nat Wooding <Nathaniel.Wooding@DOM.COM>
Subject:      Re: How to make a  macro for dynamically writing a dataset to a
              CSV-file
Comments: To: Rune Runnestø <rune@FASTLANE.NO>
In-Reply-To:  <YJadnfCJ0YMhNmDaRVnzvQA@telenor.com>
Content-Type: text/plain; charset="ISO-8859-1"

Rune

I would say that you are creating a text file rather than a CSV since you are not using a comma as the separator. The following code will create your file and you can easily stick it in a macro. If you wanted to use a different separator, you could replace the '>' with a macro variable.

data rune;

input id $2. x y z; cards; A 1 2 3 BB4 5 6 proc print; run;

Data _null_; set rune; filename new 'c:\park\TestDLM.TXT'; file new dlm = '>' ; put ( _all_ ) ('>') @1 ' '; run;

The @1 ' ' wipes out the '>' that would otherwise appear in front of the first variable.

Nat Wooding Environmental Specialist III Dominion, Environmental Biology 4111 Castlewood Rd Richmond, VA 23234 Phone:804-271-5313, Fax: 804-271-2977

Rune Runnestø <rune@FASTLANE.NO > To Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU Discussion" cc <SAS-L@LISTSERV.U GA.EDU> Subject How to make a macro for dynamically writing a dataset to a 04/10/2008 01:54 CSV-file AM

Please respond to Rune Runnestø <rune@FASTLANE.NO >

Hi, I have some datasets that I want to write to a file for each, using '<' as the field separator in the CSV-file. This is a common task, I suppose. Has anyone made a macro to simplfy it? My idea is to avoid hard-coding the column namnes in the put-statement. The variables should be written to the file in the order they have in the dataset.

I guess it would be wise to let the macro check if the sign '<' exists in any of the values in any of the records. And if it does, then skip the writing to the external file and instead output the actual record(s) to a dataset.

The input parameters for the macro could be 1) the name of the dataset 2) the delimiter sign ('<') 3) the file name (from a former filename statement) to which the dataset is written

Thanks in advance.

Regards, Rune

----------------------------------------- CONFIDENTIALITY NOTICE: This electronic message contains information which may be legally confidential and/or privileged and does not in any case represent a firm ENERGY COMMODITY bid or offer relating thereto which binds the sender without an additional express written confirmation to that effect. The information is intended solely for the individual or entity named above and access by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution, or use of the contents of this information is prohibited and may be unlawful. If you have received this electronic transmission in error, please reply immediately to the sender that you have received the message in error, and delete it. Thank you.


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