BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Zeus_Olympous
Obsidian | Level 7
Dear all, I have created a macro list (using Proc Sql). The members of this macro list are "composite" character string i.e. WORK.DSN1 WORK.DSN2 WORK.DSN3 WORK.DSN4 etc. I tried to count them by using COUNTW but the result doubles the actual number ... for each "composite" string WORK.DSN1 counts both WORK and DSN1 as separate words...I would like to my composite strings to be counted once and not be separated by "." . Any hint or advice would be lore than welcome. Thank you in advance.
1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag
Tom
Super User Tom
Super User

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( )));
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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);

Zeus_Olympous
Obsidian | Level 7
Many thank to all of you for your prompt and helpful response. Unfortunately I cannot give "the solution" remark to all of the answers

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1079 views
  • 4 likes
  • 5 in conversation