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 (July 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 6 Jul 2005 17:43:16 -0700
Reply-To:     Rob_W <weyrauch_r@YAHOO.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Rob_W <weyrauch_r@YAHOO.COM>
Organization: http://groups.google.com
Subject:      Passing a dynamic variable to a macro
Comments: To: sas-l@uga.edu
Content-Type: text/plain; charset="iso-8859-1"

I am having trouble passing the value of a variable to a macro. It almost works, but I can't think of what else to try...

I am trying to: 1. Build a directory string based on values in a Sas dataset: eg: H:\SAS\Dataset\(value from variable in table here)

2. Pass the value of the string built in step 1 to a macro

3. The macro then creates the directory if it does not already exist.

The code I have works perfectly if I pass a quoted string as the parameter, but fails if I try to pass a variable holding the necessary value. Here is the code. The WORK.SQLGOODFILES is a SAS dataset that has a SAS DateTime field named [OperationsDate]:

The log shows:

NOTE: Line generated by the macro variable "MYFILERF". 1 "md "SasDsDir

Instead of: md H:\SAS\etc. etc.

Any ideas?

==================================================== ====================================================

%macro FindOrCreateFile(myfilerf) ;

******************************************************************************; * Capture what the current option settings are, before changing them. ; ******************************************************************************; %local option_XSYNC ; %local option_NOXWAIT ;

%let option_XSYNC = %sysfunc( getoption( XSYNC, keyword ) ); %let option_NOXWAIT = %sysfunc( getoption( XWAIT, keyword ) );

******************************************************************************; *Set options as necessary for current macro ; ******************************************************************************; *XSYNC forces SAS to wait until the file is created; *NOXWAIT prevents the user from having to type "exit" at the dos prompt;

OPTIONS NOXWAIT XSYNC;

******************************************************************************; * Begin actual macro. ; ******************************************************************************;

if %sysfunc(fileexist(&myfilerf)) then do ; *File exists. Write message to log; put '*-* Directory already existed -> ' &myfilerf. ' *-*'; end ;

else do ; *Use the make directory command (md) in dos to create new directory; x "md "&myfilerf. ; put '*-* Created directory -> ' &myfilerf. ' *-*'; end ;

******************************************************************************; * Restore original option settings. ; ******************************************************************************;

OPTIONS &option_NOXWAIT &option_XSYNC ;

%mend FindOrCreateFile ;

***************; *TESTING SAMPLE; ***************;

data _null_ ;

set WORK.SQLGOODFILES;

*This works; %let myName = "H:\SAS\2005-05\DataSets" ; put 'myName->' &myName; %FindOrCreateFile(&myName) ;

*This does not; SasDsDir = "H:\SAS\" || put(OperationsDate,YYMMD7.) || "\DataSets" ; put 'SasDsDir->' SasDsDir; %FindOrCreateFile(SasDsDir) ;

run ;

==================================================== ====================================================


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