BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
%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?
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
SASPhile
Quartz | Level 8
Hi Scott,
I tried this and it worked:
%let date=%scan(&dat,2,'_')_%scan(&dat,3,'_');
ChrisNZ
Tourmaline | Level 20
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.
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
  • 3 replies
  • 2206 views
  • 0 likes
  • 3 in conversation