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
SAS Super FREQ
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!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 635 views
  • 0 likes
  • 2 in conversation