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 (February 2000, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 16 Feb 2000 14:50:36 -0500
Reply-To:     WHITLOI1 <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         WHITLOI1 <WHITLOI1@WESTAT.COM>
Subject:      Re: Can I include datafile name in the SAS command line?
Comments: To: oliver <oliver@AGYINC.COM>
Content-Type: text/plain; charset=US-ASCII

Subject: Can I include datafile name in the SAS command line? Summary: Yes, but is that the right question? Respondent: Ian Whitlock

Oliver <oliver@AGYINC.COM> wants to remove the input data set name from his SAS program and make it a parameter.

First I would suggest using a FILENAME statement and working with a named input buffer. For a test program I used

filename in "c:\junk\test.csv" ;

data _null_ ; infile in ; input ; list ; run ;

Then to remove the reference to the file I used

filename in "&sysparm" ;

data _null_ ; infile in ; input ; list ; run ;

with the run command

sas test.sas -sysparm "c:\junk\test.csv"

I also found that

filename in "!inpdat" ;

data _null_ ; infile in ; input ; list ; run ;

works with the run command

sas test.sas -set inpdat "c:\junk\test.csv"

The advantage of the latter is that the technique could be used with multiple input files by creating more SAS environment variables.

However, it is not clear that either of the above solutions is the best, since Oliver writes:

> I have to run SAS against so many different data file. I used to > replace the infile inside .sas file each time. This time i face > almost hundred different data file..

In this case I would put the program in a macro.

%macro myprog ( inp = /mnt/r1/BV2TC2/05044E263.csv ) ;

filename in "&inp" ;

data _null_ ; infile in ; input ; list ; run ;

%mend myprog ;

and then add

data _null_ ; input inp $char80. ; call execute ( '%myprog(inp=' || trim(inp) || ')' ) ; cards ; /mnt/r1/BV2TC2/05044E263.csv ... ;

Now there is only one job to submit. Of course, I would use full path names instead of depending on a working directory, but that is not essential.

Next I would find it irritating to type out one hundred file names, so I would find some means to get this done by the system. Pipes and host commands offer possibilities depending on the system and details of where where the data actually resides.

Finally, I note that Oliver did not use the DSD option on the INFILE statement in his example code. This is probably a mistake, since the DSD option causes consecutive commas to indicate missing fields and fixes other little problems when reading data with field separators.

Ian Whitlock


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