From: d-dubs on 8 Jul 2010 11:14 Is there a way in sas to put the contents of a text file to a macro variables without using a data step or a proc import step? My text file contains a single number and I have a lot of files like that. I am trying to create a macro to read all the files and use it. Pleas let me know if there is a way.
From: Patrick on 8 Jul 2010 20:23 Hi What's wrong with a data step? A common technique is to first create a data set containing all the paths and filenames you want to read from. There are many threads in this forum of how to do this, i.e. http://groups.google.com.au/group/comp.soft-sys.sas/browse_thread/thread/e264111a6dc2b03b/7f22e22a24bf5c1c?hl=en&lnk=gst&q=filename+pipe+dirlist#7f22e22a24bf5c1c And then use this list of files and read then in a subsequent data step as shown here: http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000146932.htm#a000177201 If the values need to be put into macro variables then just use a 'call symput()' in the second data step. You haven't told us what you need all these source values for - and why they need to be in macro vars. If you can: Use by group processing instead of (macro-) looping over some procedure. HTH Patrick
From: Lou on 8 Jul 2010 20:32 "d-dubs" <m.denniswilliams(a)gmail.com> wrote in message news:a7d0cf14-0637-4a02-9eaa-fba49058e617(a)w12g2000yqj.googlegroups.com... > Is there a way in sas to put the contents of a text file to a macro > variables without using a data step or a proc import step? > My text file contains a single number and I have a lot of files like > that. I am trying to create a macro to read all the files and use it. > Pleas let me know if there is a way. You want a program to use the contents of a file without reading it? If the text file is named "fee.txt" and contains something like: %let fie = 45; you can %include the file, and the macro variable &fie will have the value "45". But if it contains just the number 45, you'll have to read the file (I'd use a data step) and use something like CALL SYMPUT to assign the number to a macro variable.
From: Arthur Tabachneck on 9 Jul 2010 18:40 Dennis, I don't know if this might help you in your effort, but your post reminded me of an old Paul Dorfman post that indicated that one could import delimited text files using proc sql. As such, I posted the question of how to do that over on the listserv side of SAS-L. You can see the various responses at: http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1007b&L=sas-l&D=1&O=D&P=11347 Thanks Randy, Tom, Kevin and Chang! Nice ideas and I, for one, got to learn something new today. Anyhow, since I'm still on 9.1.3, I used Randy's suggested code. I think it could easily be generalized to your desired solution with such extras as a pipe to define the files to read, call execute, building an include file, and/or developing a macro. I used: proc sql noprint; create table number (keep=number) as select ' ' as number, filename('txtFile','c:\thetext.txt') as sysrc1, fopen('txtFile') as fid, fread(calculated fid), fget(calculated fid, calculated number), fclose(calculated fid) as sysrc2, filename('txtFile',' ') as sysrc3 from sashelp.class where name='Alfred' ; select number into :number from number ; quit; %put &number; HTH, Art ------------ On Jul 8, 11:14 am, d-dubs <m.denniswilli...(a)gmail.com> wrote: > Is there a way in sas to put the contents of a text file to a macro > variables without using a data step or a proc import step? > My text file contains a single number and I have a lot of files like > that. I am trying to create a macro to read all the files and use it. > Pleas let me know if there is a way.
|
Pages: 1 Prev: Newbie Interview question Next: binomial function in proc model |