BookmarkSubscribeRSS Feed
SAS_user_n
Calcite | Level 5
Hi,

I am trying to use the following macro to name my data file but it is not working but not sure why. It gets stuck on "data temp_&yymm._seg&i". It seems to get stuck due to having 2 macro variables in the file name.

Could I get some help? Thank you.
================================
%macro name_data(yymm=,i=);

data temp_&yymm_seg&i ;

merge data1_seg&i (in=a)
data2_&yymm_seg&i (in=b);

by common_var;

run;
%mend name_data;
2 REPLIES 2
Cynthia_sas
Diamond | Level 26
Actually, there is a HUGE difference between:
temp_&yymm._seg&i as a macro variable reference (with the dot[.] ) and temp_&yymm_seg&i without the dot [.] in the name.

Your code does NOT show the dot. I would suspect that you are getting messages something like this:
[pre]
WARNING: Apparent symbolic reference YYMM_SEG not resolved.
[/pre]

Or something similar if you do NOT have a single dot that shows the macro processor where one macro variable ends and the rest of the string begins. If you need to have a dot in a resolved macro variable name, such as you needed to build a dataset name from 2 macro variables, then you use 2 dots -- one dot for the delimiter and the second dot as part of the resolved value, like this:
[pre]
%let lib = perm;
%let myfile = cars;

proc print data=&lib.&myfile <---would be wrong
proc print data=&lib..&myfile <---would be correct
[/pre]

For more information about macro variable concatenation to build text strings from multiple macro variables, consult the macro documentation. In addition, this paper is a good introduction to macro processing concepts.
http://www2.sas.com/proceedings/sugi28/056-28.pdf

cynthia
SAS_user_n
Calcite | Level 5
I just saw your reply and thank you for your reply, Cynthia!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1246 views
  • 0 likes
  • 2 in conversation