DATA Step, Macro, Functions and more

%let and Scan Function!

Reply
Super Contributor
Posts: 647

%let and Scan Function!

%let dat=Abc_2009_05;
%let date=scan("&dat",2,'_')||'_'||scan("&dat",3,'_');

What is to be done to make &date to resolve to 2009_05?
Super Contributor
Super Contributor
Posts: 3,174

Re: %let and Scan Function!

If you have a standardized character string format, you can generalize your code to %INDEXC the first occurence of "_" and then %SUBSTR from there. The use of SCAN is incorrect as you have described in your posted code, by the way.

Scott Barry
SBBWorks, Inc.
Super Contributor
Posts: 647

Re: %let and Scan Function!

Hi Scott,
I tried this and it worked:
%let date=%scan(&dat,2,'_')_%scan(&dat,3,'_');
PROC Star
Posts: 1,562

Re: %let and Scan Function!

It should be [pre]
%let date=%scan(&dat,2,_)_%scan(&dat,3,_); [/pre]
You are using ' as delimiters in your example, which you don't need or mean to.
Ask a Question
Discussion stats
  • 3 replies
  • 141 views
  • 0 likes
  • 3 in conversation