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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 5 replies
  • 799 views
  • 4 likes
  • 5 in conversation