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,
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;
What do you mean excludes them from the results? What are you getting, versus, what do you expect?
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;
THanks!!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.