From: Matt C on 6 May 2010 22:34 Hi All, I have a situation where I have some 20+ files that need to be 'processed' using the same script. Although it is possible to change out some 3 or 4 times that I call for an individual file I know that there must be a better way. I have thought about using arrays but I am having a little trouble conceptualizing it fully, (too tired??). For example: Array file(*) n1---n24; file(1) = file_name_1; file(2) = file_name_2; .... Run; Do I = 1 to 24; Data new(I); Set file(I); Proc X; Run; End; Is this the best way to do this or is there a simpler way?? Cheers, M
From: Steve James on 10 May 2010 12:48 On May 6, 10:34 pm, Matt C <matt.curcio...(a)gmail.com> wrote: > Hi All, > I have a situation where I have some 20+ files that need to be > 'processed' using the same script. Although it is possible to change > out some 3 or 4 times that I call for an individual file I know that > there must be a better way. > > I have thought about using arrays but I am having a little trouble > conceptualizing it fully, (too tired??). > For example: > > Array file(*) n1---n24; > file(1) = file_name_1; > file(2) = file_name_2; > ... > Run; > > Do I = 1 to 24; > Data new(I); > Set file(I); > Proc X; > Run; > End; > > Is this the best way to do this or is there a simpler way?? > Cheers, > M There are several ways to do this. What might be the simplest is to put the code that you want to run repeatedly into a macro and have the dataset name as a parameter to the macro. %macro process(dsn) ; data temp ; set &dsn ; <more code> ; proc x ; etc. %mend process ; * Now run the process for each file ; %process(file_name_1) ; %process(file_name_2) ; etc ; There are more elegant ways to call the macro for each file, but most of them end up doing in a slightly more automated way what this does explicitly. With a good text editor and only 20 or so filenames this will be about as quick and it's clearer what's going on. Steve
From: Reeza on 10 May 2010 17:44 On May 6, 7:34 pm, Matt C <matt.curcio...(a)gmail.com> wrote: > Hi All, > I have a situation where I have some 20+ files that need to be > 'processed' using the same script. Although it is possible to change > out some 3 or 4 times that I call for an individual file I know that > there must be a better way. > > I have thought about using arrays but I am having a little trouble > conceptualizing it fully, (too tired??). > For example: > > Array file(*) n1---n24; > file(1) = file_name_1; > file(2) = file_name_2; > ... > Run; > > Do I = 1 to 24; > Data new(I); > Set file(I); > Proc X; > Run; > End; > > Is this the best way to do this or is there a simpler way?? > Cheers, > M Macro programming as suggested above. A text editor the first few times is recommended, but that gets tedious as well after the first 20 times... See http://www2.sas.com/proceedings/sugi29/243-29.pdf Cheers, Reeza
|
Pages: 1 Prev: test if a median is significantly different from zero Next: Call Symput during execution? |