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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 3 replies
  • 2283 views
  • 0 likes
  • 3 in conversation