Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

What is wrong with Call symput()?

What is wrong with Call symput()?

What is wrong with Call symput()?

Hi, Any one can tell why I could not get my macro variables resolved? Sometimes it worked. Pls see below log.  Thanks, Mike
133  %macro aa (_var= xyz0103-xyz0108);
134    DATA varname ;
135    do j=1 to 2;
136      varname=scan( "&_var",j,'-');
137        CALL SYMPUT('tmpvar'||left(j),varname);
138        output;
139    end;
140    RUN;
141  %mend aa;
142  %aa;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
NOTE: The data set WORK.VARNAME has 2 observations and 2 variables.
NOTE: DATA statement used:
      real time           0.02 seconds
      cpu time            0.02 seconds

WARNING: Apparent symbolic reference TMPVAR1 not resolved.
WARNING: Apparent symbolic reference TMPVAR2 not resolved.
143  %put tmevar= &tmpvar1 &tmpvar2;
tmevar= &tmpvar1 &tmpvar2

RE: What is wrong with Call symput()?

Try this:
    DATA _null_;
    %macro aa (_var= xyz0103-xyz0108);
    do j=1 to 2;
        varname=scan( "&_var",j,'-');
        CALL SYMPUT('tmpvar'||left(j),varname);
    %mend aa;
 You may want to add a trim function to varname to remove trailling blanks.

SYMPUT puts the macro variable in the most local nonempty symbol table. The first time you run you macro, macro variables are created as local macro variables. %put statement is out of the scope of the macro variable. But when you run your macro the second time, local symbol table is not empty any more. Macro variables are created in the nearest nonempty symbol table, in your case, there is no next level of local macro variable table. Therefore, they are created in the globle macro variable table. That is why your code does not work the first time. It works after the first time.

RE: What is wrong with Call symput()?

Thanks Teralearner,  you're right.  A macro varible created by SYMPUT()must be used only after RUN statement.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close