BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Batman
Quartz | Level 8

I have a macro array of formats, however the %scan function is dropping the "$" and ".", how can I get %scan to read those characters?

 

 

27 %put macro array of format values is &formats;
macro array of format values is $2. 8. $6. $55. DATETIME19. DATETIME19. $1.
28 %put fourth scanned format value is %scan(&formats,4);
fourth scanned format value is 55

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Specify that %scan should only use a blank, %str( ) as the delimiter, e.g.:

1    %let formatlist=$2. 8. $6. $55. DATETIME19. DATETIME19. $1.  ;
2    %put %scan(&formatlist,4,%str( )) ;
$55.
The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

View solution in original post

2 REPLIES 2
Quentin
Super User

Specify that %scan should only use a blank, %str( ) as the delimiter, e.g.:

1    %let formatlist=$2. 8. $6. $55. DATETIME19. DATETIME19. $1.  ;
2    %put %scan(&formatlist,4,%str( )) ;
$55.
The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
ballardw
Super User

Read the friendly manual. The documentation for %scan includes this bit clearly showing that the $ character by default treated as a delimiter.

If you use the %SCAN function with only two arguments, then the default delimiters depend on whether your computer uses ASCII or EBCDIC characters.
  • If your computer uses ASCII characters, then the default delimiters are as follows:
    blank ! $ % & ( ) * + , - . / ; < ^¦
    In ASCII environments that do not contain the ^ character, the %SCAN function uses the ~ character instead.
  • If your computer uses EBCDIC characters, then the default delimiters are as follows:
    blank ! $ % & ( ) * + , - . / ; < ¬ | ¢¦

 

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 449 views
  • 2 likes
  • 3 in conversation