Not sure if you tried to include the delimiter in countw function as below
data have;
length string $100.;
string='WORK.DSN1 WORK.DSN2 WORK.DSN3 WORK.DSN4';
c=countw(string,' ');
run;
Not sure if you tried to include the delimiter in countw function as below
data have;
length string $100.;
string='WORK.DSN1 WORK.DSN2 WORK.DSN3 WORK.DSN4';
c=countw(string,' ');
run;
You need to give the COUNTW() function the optional third argument that specifies what charater(s) to consider the delimiter between words.
%put %sysfunc(countw(a.b c.d,%str( )));
use COUNTW function with ' ' as second parameter
In the same step as you create the macro list just add:
select count(*) from SASHELP.VTABLES where LIBNAME="WORK" and memname like "DSN%";
In fact, you could use the data returned from the metadata to directly work with, taking out a layer of abstraction:
E.g.:
data _null_; set sashelp.vtable (where=(libname="WORK" and substr(memname,1,3)="DSN")); call execute('%do_somthing(indata='||strip(name)||';'); run;
This would generate a % call for each dataset fulfilling the where clause, in your example, for example:
%do_something(indata=dsn1);
%do_something(indata=dsn2);
%do_something(indata=dsn3);
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!
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.