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 (January 2012, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 27 Jan 2012 20:37:55 -0600
Reply-To:     Joe Matise <snoopy369@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Joe Matise <snoopy369@GMAIL.COM>
Subject:      Re: extract information from File name?
Comments: To: help ly <help.ly2005@gmail.com>
In-Reply-To:  <CA+bt8+1Ua217VMi25r9erOHimFTbY7-cvuzpU-uLfcjgbY2Ogw@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

There is a filename option on the infile statement that will do what you want, though you need to create an additional variable if you want to keep it, as the filename=<variable> will not be written to the dataset.

-Joe

data want; length file_name $50; infile "c:\temp\*.csv" filename=file_name; file_name_ds = file_name; run;

On Fri, Jan 27, 2012 at 7:46 PM, help ly <help.ly2005@gmail.com> wrote:

> Hi Everyone, > > I am reading lots of files in SAS, such as: > corp1.csv > corp2.csv > corp3.csv > corp4.csv > ............ > > filename Files '/srf/*.txt'; > data out.Data; > infile Files......; > > I will need get the Company name from the individual file name, and insert > a column in each data set after reading the txt file. For example, after > Data from corp1.csv is read, I would like to add a variable CompanyName as > "corp1". > > Is there an efficient way to extract that part of information from each > individual File name while reading the whole set? > > -- > Thanks so much! > > Orange > help.ly2005@gmail.com >


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