DATA Step, Macro, Functions and more

macro to find file location

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

macro to find file location

I'm trying to write some code that will generate today's date then add that to a string to search for a file matching that date.  Problem I'm having is the concatenation of the string is producing spaces before the macro despite trying different trim options.  Been a few years since working with SAS so I'm rusty.

 

data _null_ ;

x = date() ;

format x yymmdd10. ;

xx = compress(put(x, yymmdd10.), '-') ;

call symput('datepull', xx ) ;

call symput('testfile', "\\vanfile\EnterpriseBusinessIntelligence\Tools Stuff\External Source Files\Casino\PlayPlanner\PlayerExtract_Precommitment_"||&datepull||'000000.xls');

/* call symput('testfile', "Casino\PlayPlanner\PlayerExtract_Precommitment_"||&datepull||'000000.xls');*/

run;

%put &datepull ;

%put &testfile ;

 

 

41 %put &datepull ;

20180608

42 %put &testfile ;

\\vanfile\EnterpriseBusinessIntelligence\Tools Stuff\External Source Files\Casino\PlayPlanner\PlayerExtract_Precommitment_

20180608000000.xls


Accepted Solutions
Solution
a week ago
Respected Advisor
Posts: 2,794

Re: macro to find file location

Posted in reply to paulsparrow

Use CALL SYMPUTX instead of CALL SYMPUT

--
Paige Miller

View solution in original post


All Replies
Solution
a week ago
Respected Advisor
Posts: 2,794

Re: macro to find file location

Posted in reply to paulsparrow

Use CALL SYMPUTX instead of CALL SYMPUT

--
Paige Miller
Contributor
Posts: 20

Re: macro to find file location

Posted in reply to PaigeMiller

Thanks.

Super User
Posts: 6,622

Re: macro to find file location

Posted in reply to paulsparrow

You have a couple of issues, beginning with the fact that &DATEPULL doesn't exist when it is needed to create &TESTFILE.  I would recommend a two-step fix.

 

First, remove all reference to &DATEPULL from the DATA step.

 

Then create &TESTFILE after the DATA step is over, using two statements:

 

%let datepull = &datepull;

%let testfile = \\vanfile\EnterpriseBusinessIntelligence\Tools Stuff\External Source

Files\Casino\PlayPlanner\PlayerExtract_Precommitment_&datepull.000000.xls;

 

The first %LET will remove any leading or trailing blanks from &DATEPULL.  The second %LET creates the string you need, but double-check the spacing to make sure I got it right (particularly this part:  External Source Files).

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 117 views
  • 0 likes
  • 3 in conversation