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

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.

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