Help using Base SAS procedures

Using substr within a %let definition?

Super Contributor
Posts: 405

Using substr within a %let definition?

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.

%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 ;

This is the text from the log

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)
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


Thank you for any help
Frequent Contributor
Posts: 139

Re: Using substr within a %let definition?

Posted in reply to jerry898969
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
Super Contributor
Posts: 405

Re: Using substr within a %let definition?

Posted in reply to darrylovia

That was it thanks so much for the quick reply.
Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation