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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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