BookmarkSubscribeRSS Feed
jerry898969
Pyrite | Level 9
I would like to create a macro variable based on a different macro variable is this possible? I need to use a part of the filename macro variable to create another one to use as a way to name my data set.

[pre]
%let filename = ABCDE1234 ;
%let path = c:\temp\ ;
%let filenm = substr("&filename.",1,5) ;

options symbolgen ;

filename indata "&path&filename..txt";


data &filenm ;
infile indata dsd truncover;
input num ?? @ ;
do while( num ne . );
output ;
input num ?? @ ;
end ;
run ;
[/pre]

This is the text from the log

[pre]
SYMBOLGEN: Macro variable FILENM resolves to substr("ABCDE1234",1,5)
544 data &filenm ;
NOTE: Line generated by the macro variable "FILENM".
1 substr("ABCDE1234",1,5)
-----------
22
ERROR 22-7: Invalid option name "ABCDE1234".

545 infile indata dsd truncover;
546 input num ?? @ ;
547 do while( num ne . );
548 output ;
549 input num ?? @ ;
550 end ;
551 run ;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

[/pre]

Thank you for any help
2 REPLIES 2
darrylovia
Quartz | Level 8
You need to use a macro function not a data step function


%let filenm=%substr(&filename,1,5);

This should get what you are looking for
jerry898969
Pyrite | Level 9
darry,

That was it thanks so much for the quick reply.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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