BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
belboy
Obsidian | Level 7

Hi,

I'm running a DO LOOP but SAS keeps deleting two observations that I need to keep in my results.  For example, this is my dataset:

 

RACF                           GROUPS

USDISEF                      MKZ;admin;FF

EOR_E47 ACCT           %

USI43_SK                     RETSIPX;dba

UT_ACCT C47              %

 

%let folder = work.IMG;
%let loop = GROUPS;


/*STEP 1 - Creates DO Loop necessary for possible combined columns in complex files.*/


data Do_&appname;
set &folder;

x = countw(&loop);
do i = 1 to x;
&loop.1 = scan(&loop, i, ";");
output;
END;
run;

 

I get the results as needed with the exception of  EOR_E47 ACCT  and   UT_ACCT C47  .  SAS excludes these from the results.  How can I get them included with a value of "%"?

 

Any help is much appreciated.

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

First I think you need to describe a bit more of what this is supposed to do.

 

The issue is documented in the documentation for the Countw function of "what is a word":

"word" refers to a substring that has one of the following characteristics: 
• is bounded on the left by a delimiter or the beginning of the string 
 
•is bounded on the right by a delimiter or the end of the string 
 
•contains no delimiters, except if you use the Q modifier and the delimiters are within substrings that have quotation marks 

The last one is the cause of your problem as delimiters for countw are:

 

If your computer uses ASCII characters, then the default delimiters are as follows: 
 
blank ! $ % & ( ) * + , - . / ; < ^ | 

So since your value is % that is a delimiter and countw("%",1) returns 0. And the do loop becomes:

 

do I = 1 to 0; so it never actually loops.

Since that, hopefully, would be a special case you could use something like

data Do_&appname;
   set &folder;
   x = countw(&loop);
   if x>0 then    do i = 1 to x;
   &loop.1 = scan(&loop, i, ";");
      output;
   END;
   else do;
      &loop.1=&loop;
      output;
   end;
run;

View solution in original post

3 REPLIES 3
Reeza
Super User

What do you mean excludes them from the results? What are you getting, versus, what do you expect?

ballardw
Super User

First I think you need to describe a bit more of what this is supposed to do.

 

The issue is documented in the documentation for the Countw function of "what is a word":

"word" refers to a substring that has one of the following characteristics: 
• is bounded on the left by a delimiter or the beginning of the string 
 
•is bounded on the right by a delimiter or the end of the string 
 
•contains no delimiters, except if you use the Q modifier and the delimiters are within substrings that have quotation marks 

The last one is the cause of your problem as delimiters for countw are:

 

If your computer uses ASCII characters, then the default delimiters are as follows: 
 
blank ! $ % & ( ) * + , - . / ; < ^ | 

So since your value is % that is a delimiter and countw("%",1) returns 0. And the do loop becomes:

 

do I = 1 to 0; so it never actually loops.

Since that, hopefully, would be a special case you could use something like

data Do_&appname;
   set &folder;
   x = countw(&loop);
   if x>0 then    do i = 1 to x;
   &loop.1 = scan(&loop, i, ";");
      output;
   END;
   else do;
      &loop.1=&loop;
      output;
   end;
run;
belboy
Obsidian | Level 7

THanks!!

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
  • 3 replies
  • 863 views
  • 0 likes
  • 3 in conversation