DATA Step, Macro, Functions and more

Resolve macro variables

Reply
Contributor
Posts: 65

Resolve macro variables

Hi,

 

I have macros string1, string2, string3 declared and initialized in code and I want to send the control to a labeled section which will put them in a message box. However, the do loop in the message box is unable to retrieve the value of macro variable by using the statement:-

commandlist=insertc(commandlist,string!!i,i);

here is the main part of the code:-

%let string1;
%let string2;
%let string3; %let n; if anyspace(selpath) then do; string1="Path Should Not Contain Blank Spaces";
string2="select another path"; n=1; link errormsg; tmp_lstbtn._cursor(); return; end; errormsg: commandlist=makelist(); do i=1 to n; commandlist=insertc(commandlist,string!!i,i); end; command=messagebox(commandlist,'S','O',"ERROR: Header Generator"); commandlist=dellist(commandlist); return;

 Please suggest a method to get the string values iteratively so that it could be inserted int he list.

Super User
Posts: 6,928

Re: Resolve macro variables

With the exception of the 4 %let commands, this is all data step code. I guess you're confusing data step code with macro code.

 

string1 ist not equal to &string1 !!!!

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,392

Re: Resolve macro variables

Can I suggest you post some test data, and what you want the output to look like.  You may also want to clarify what software you are using, as this doesn't look like Base SAS, this is a function call:

         tmp_lstbtn._cursor();       

 

Contributor
Posts: 65

Re: Resolve macro variables

Note: This is a snippet from SAS Component Language.

Super User
Super User
Posts: 7,392

Re: Resolve macro variables

Ah, so your using AF/SCL.  Unfortunately I am not able to help here then, I haven't used it in many years.  Am surprised its still being used to be honest.  You will probably find that there are currently better methods nowadays if you want to do app deverlopment.  

Super User
Posts: 6,928

Re: Resolve macro variables

Could you provide the corresponding piece of log?

 

I have a feeling that this:

string!!i

won't work as you expect, as it will try to concatenate the contents of STRING with the contents of I (instead of giving you the contents of string1 or string2 or string3 and so on)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,392

Re: Resolve macro variables

Yes, I think you have hit the nail on the head there KurtBremser.  The INSERTC command takes this form:

rc=INSERTC(list-id,cval<,index<,name>>);

 

Now what is appears he is trying to do is use the iterator i to indicate if the value should be string1 or string2.  As I said its been a long time since I used this, so am fixed on arrays, or macro.  However the question I would say is why have string1/2/3 etc. as macro variables in the first place.  Why not insert these into a list of thier own:

   if anyspace(selpath) then do;
      stringlist=makelist();
      stringlist=insertc(stringlist,"Path Should Not Contain Blank Spaces",1);
      stringlist=insertc(stringlist,"select another path",2);
      link errormsg;                                                                                                                                                                                                                   
      tmp_lstbtn._cursor();                                                                                                                                                                                                                               
      return;                                                                                                                                                                                                                                             
   end;

SCL lists are the method for handling lists of values, so use them rather than creating macro variables?

 

Ask a Question
Discussion stats
  • 6 replies
  • 262 views
  • 1 like
  • 3 in conversation