BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
genemroz
Quartz | Level 8

I'm trying to use a macro variable as part of a dataset name and not having any success.  Here's a simplifed version of what I'm trying to do that generates a Syntax Error message .  I want to get a dataset name of 'US000D_output'. I'm missing something simple but it is eluding me.

Thanks in advance for any help you can provide,

Gene

data input;
Length text $30 station $6;
Text='/Prefix/US000D/Suffix/';
Station=scan(text,2);
Call symput('StationID',Station);
put &StationID;
run;

data &StationID_output;
set input;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kathryn_SAS
SAS Employee

You need a period to tell SAS where the macro variable name stops. Also a macro variable created with CALL SYMPUT will not resolve until a step boundary is reached.

data input;
Length text $30 station $6;
Text='/Prefix/US000D/Suffix/';
Station=scan(text,2);
Call symput('StationID',Station);
run;
%put &StationID;

data &StationID._output;
set input;
run;

View solution in original post

4 REPLIES 4
Kathryn_SAS
SAS Employee

You need a period to tell SAS where the macro variable name stops. Also a macro variable created with CALL SYMPUT will not resolve until a step boundary is reached.

data input;
Length text $30 station $6;
Text='/Prefix/US000D/Suffix/';
Station=scan(text,2);
Call symput('StationID',Station);
run;
%put &StationID;

data &StationID._output;
set input;
run;
genemroz
Quartz | Level 8
Yes, as simple as a simple period. Thanks for your help.
Gene
ballardw
Super User

You might also want to consider making sure that the resolved name doesn't exceed the SAS naming limits. Nothing like trying to use "too_long_of_a_macrovariable_output" only to later find the actual name of the data set is "too_long_of_a_macrovariable_out" because of the 32 character limit.

 

Similar considerations are in effect for Library, Catalog and File reference names.

Tom
Super User Tom
Super User

You should only use the ancient CALL SYMPUT() routine when it is important that leading and/or trailing spaces be put into the macro variable.

 

Instead use its replacement the CALL SYMPUTX() routine.

 

If it worked for you it is only because the result of the SCAN() function call completely filled the variable STATION which you defined as length $6.  If STATION had been defined longer or the value pulled out of TEXT had been shorter you would have put one or more trailing spaces into the macro variable STATIONID.

 

In which case your data step would have made two output datasets since you would have told SAS to run something like:

data U0000D     _output ;

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 162 views
  • 2 likes
  • 4 in conversation