DATA Step, Macro, Functions and more

Use environment string as variable name

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 124
Accepted Solution

Use environment string as variable name

Greetings all.  I'm wanting to use SAS to call a VBScript file in a user's temp directory.  After some googling, I found what I think should work, but I keep getting errors.  In the below code, I am using %sysget(temp) to get the path, but then I want to append it with '\filename.vbs', but I am getting a 'not resolved error.  Could anyone explain why?  Thank you.

%let temp_path = %sysget(temp) ;

data _null_ ;

    %put &temp_path ;

    call symput('file_name',cat("'",&tpath,"\file_name.vbs","'")) ;

    %put &file_name ;

run ; quit ;

Greg


Accepted Solutions
Solution
‎02-14-2014 07:50 AM
Respected Advisor
Posts: 3,777

Re: Use environment string as variable name

Do you need CALL SYMPUT?

%let temp_path = %sysget(temp);
%let file_name = &temp_path\vbs_file.vbs;

View solution in original post


All Replies
Super User
Posts: 10,550

Re: Use environment string as variable name

Move the %put statement OUT of the data step. The macro variable is not actually available until the datastep completes.

Generally you can't reference created macro variables in a datastep that creates them.

Frequent Contributor
Posts: 124

Re: Use environment string as variable name

Thank you ballardw.  I had the %put in there just so I could verify that the temp_file variable was being correctly assigned.  It seems the real issue is when I try to use it in the symput routine.  If I move the symput into it's own data step, that's where I get the issue...

* no problems here, temp_path assigned as expected ;

%let temp_path = %sysget(temp) ;

data _null_ ;

    %put &temp_path ;

run ; quit ;

* now, when I try to use temp_path in a symput routine, I get error ;

data _null_ ;

     call symput('file_name',cat(&temp_path,'\vbs_file.vbs')) ;

run ; quit ;

ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

What I would like to happen is to end up with a file_name variable eq 'C:\Users\username\AppData\Local\Temp\1\vbs_file.vbs', so that I can then use the file_name variable to write create, write to, then execute like below

data _null_ ;

    x &file_name ;

run ; quit ;

Solution
‎02-14-2014 07:50 AM
Respected Advisor
Posts: 3,777

Re: Use environment string as variable name

Do you need CALL SYMPUT?

%let temp_path = %sysget(temp);
%let file_name = &temp_path\vbs_file.vbs;
Frequent Contributor
Posts: 124

Re: Use environment string as variable name

Thank you so much data_null_;.  Once again, I was over complicating it.  I put it in the symput because I need it for other stuff, and I figured that since it was already there, why not.  Thank you.

Greg

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 322 views
  • 0 likes
  • 3 in conversation