BookmarkSubscribeRSS Feed
Aditi24
Obsidian | Level 7

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.

6 REPLIES 6
Kurt_Bremser
Super User

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 !!!!

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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();       

 

Aditi24
Obsidian | Level 7

Note: This is a snippet from SAS Component Language.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

Kurt_Bremser
Super User

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)

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 948 views
  • 1 like
  • 3 in conversation