Hello,
I have silly question: what does following code try to get?
%scan (&_indata,1,%str( %())
it looks like it try to get the 1st segment of &_indata.. I feel confused on the part of "%str( %()". Could anyone interpretate that for me, especially the part with % and (.
Thanks.
Maxim#1: Read the documentation
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0pnc7p9n4h6g5n16g6js048nhfl.htm
Bart
The third position of the scan and %scan is the list of characters used as delimiters. So someone wanted to set the list characters to include the % sign as well as space and the parentheses as delimiters. Because the macro language uses % as a special character they needed to use the %str() to prevent using that % in the list as a macro trigger.
By default %scan would use any of the following as delimiters:blank ! $ % & ( ) * + , - . / ; < ^¦
So one suspects that one or more of those characters were expected to appear in the values and they did not want those others to be treated as delimiters.
It extracts the dataset name from a macro variable that might hold a dataset name with dataset options.
Example:
%let inds=sashelp.class(drop=age);
%let ds_only = %scan(&inds,1,%str( %());
Results
1 %let inds=sashelp.class(drop=age); 2 %let ds_only = %scan(&inds,1,%str( %()); 3 %let libname = %upcase(%scan(work.&ds_only,-2,.)); 4 %let memname = %upcase(%scan(&ds_only,-1,.)); 5 %put &=inds &=ds_only &=libname &=memname; INDS=sashelp.class(drop=age) DS_ONLY=sashelp.class LIBNAME=SASHELP MEMNAME=CLASS 6 7 %let inds=class; 8 %let ds_only = %scan(&inds,1,%str( %()); 9 %let libname = %upcase(%scan(work.&ds_only,-2,.)); 10 %let memname = %upcase(%scan(&ds_only,-1,.)); 11 %put &=inds &=ds_only &=libname &=memname; INDS=class DS_ONLY=class LIBNAME=WORK MEMNAME=CLASS
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.