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 (June 1996, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 3 Jun 1996 09:07:39 GMT
Reply-To:     Netnews Server <NETNEWS@AMERICAN.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Netnews Server <NETNEWS@AMERICAN.EDU>
Organization: BASF Aktiengesellschaft
Subject:      Re: Dynamic Filenames

Hi, Tony!

Maybe the following macro will help you:

%macro outfile(m_max);

%do m_i = 1 %to &m_max; %let m_fn_&m_i = ; %end;

data cust; input @1 custno $4. @1 allvars $char100.; cards; 1111 asljkf sdlfjk sfdljk 1111 asfljksdalk sdfkljsdf 1111 sfdlk fsjkl fsdjkl 2222 asljkf sdlfjk sfdljk 2222 sfljksdalk sdfkljsdf 3333 sfdlk fsjkl fsdjkl 3333 asljkf sdlfjk sfdljk ; run;

proc sort data=cust out=custno(drop=allvars) nodupkey; by custno; run;

data _null_; set custno; call symput('m_fn_'||compress(put(_n_,1.)),put(custno,$4.)); run; %do m_i = 1 %to &m_max; %if (&&&m_fn_&m_i ne ) %then %do; filename cust&&&m_fn_&m_i "data.file.cust&&&m_fn_&m_i"; %end; %end; filename other "data.file.other";

data _null_; set cust; select (custno); %do m_i = 1 %to &m_max; %if (&&&m_fn_&m_i ne ) %then %do; when ("&&&m_fn_&m_i") file cust&&&m_fn_&m_i; %end; %end; otherwise /* in case I missed anything */ file other; end; put @1 allvars $char100.; run; %mend outfile;

First your cards are read into a dataset CUST. To get all possible values for CUSTNO it is sorted by CUSTNO. The result is a dataset CUSTNO which contains all values for CUSTNO. With the help of this dataset a series of macro variables is created. They are used to create the filename statements and the different statements in your select-block.

The parameter M_MAX gives the maximal amount of unique customur numbers. If you expect 20 unique numbers you call the macro with

%outfile(20)

Hope it will help you

Steffen Lucas


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