BookmarkSubscribeRSS Feed
Lakshmi_G90
Calcite | Level 5

Hi All,

Greetings for the day !!

I have been working on a macro variable called "value" which holds directory paths and some macro names in it.

Example:

Value

sas\\states\test.txt

operations.sas.klist

%OPRMN

 

data _null_;
i=0;
do until((&var. = " ") or (&value.= " "));
i=i+1;
call symput('scan("&Var.",i,"*")','scan("&value.",i,"*")' );
output;
end;
run;

 

Here,  \\, . these characters in Value variable are causing the issue and throwing the below error.

ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.

ERROR 200-322: The symbol is not recognized and will be ignored.

Can any one please suggest me on this issue.

Looking forward for the solution

 

Thanks in advance !

 

 

 

 

 

7 REPLIES 7
Kurt_Bremser
Super User

What are the contents of macro variables &var and &value?

In this step:

data _null_;
i=0;
do until((&var. = " ") or (&value.= " "));
i=i+1;
call symput('scan("&Var.",i,"*")','scan("&value.",i,"*")' );
output;
end;
run;

they need to resolve to string literals (text in quotes) or variable names to be syntactically correct.

But, since you do not have any incoming data (either from a dataset or an external file), there are no data step variables to use, so variable names make no sense.

In the data you posted in the first part:

Value

sas\\states\test.txt

operations.sas.klist

%OPRMN

there is nothing that resembles a string literal, so it can't be that, either.

 

What are you trying to achieve?

Lakshmi_G90
Calcite | Level 5

Hi KurtBremser ,

Thanks for your response.

Var and value are of my 2 macro variables which are having data as below.

 

Var

--------

a

b

c

 

 

Value

----------------

sas\\states\tax\cose\test.txt

operations.sas.klist

%OPRMN

 

I'm trying to create a, b, c macro variables by using call symput and pass the values respectively from the another variable called "VALUE" (sas\\states\tax\cose\test.txt,  operations.sas.klist,   %OPRMN) .

 

For this I have written the previous code which is causing error in reading single '\' and '.' 

I used %nrstr, %nrbquote functions also, still no luck.

 

Kurt_Bremser
Super User

Use a dataset with name/value pairs, and then it is simple and works:

data lookup;
input name :$10. value :$50.;
datalines;
a sas\\states\tax\cose\test.txt
b operations.sas.klist
c %OPRMN
;

data _null_;
set lookup;
call symputx(name,value,'G');
run;

%put _user_;

partial log:

 85         
 86         %put _user_;
 GLOBAL A sas\\states\tax\cose\test.txt
 GLOBAL B operations.sas.klist
 GLOBAL C %OPRMN
Lakshmi_G90
Calcite | Level 5

Many thanks for the solution.
Could you please let me know what was wrong in my previous code, why the \, . were not getting read by SAS.
I was doing this by using macro variables, but getting error. Can't we do this with macro variables..?

Kurt_Bremser
Super User

Doing it from macro variables is possible, but you get WARNINGs for data that looks like macro triggers:

%let var=a*b*c;
%let value=sas\\states\tax\cose\test.txt*operations.sas.klist*%OPRMN;

data _null_;
do i = 1 to countw("&var.","*");
  call symput(scan("&var.",i,"*"),scan("&value.",i,"*"));
end;
run;

%put _user_;
Lakshmi_G90
Calcite | Level 5

Many Thanks KurtBremser  and Tom  🙂

Tom
Super User Tom
Super User

This line looks wrong.

call symput('scan("&Var.",i,"*")','scan("&value.",i,"*")' );

You are asking SYMPUT to create a macro variable whose name includes invalid characters like ("&.*,).

Did you want to call the data step function SCAN?  If so then don't put it inside of quotes.

call symput(scan("&Var.",i,"*"),scan("&value.",i,"*") );

There is no need to build your own iteration logic. SAS has an iterative DO loop.

do i=1 to countw("&var.","*");

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1663 views
  • 0 likes
  • 3 in conversation