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);
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.