Hi,
i have used the talent dataset. Could someone tell me why there is a difference between x and y results?
data tp;
set sasuser.talent;
blank=strip(Agency);
x=countc(blank," ");
y=countc(strip(Agency)," ");
keep blank x y Agency;
run;
results
Obs Agency blank x y
1 TALENT TALENT TALENT TALENT TALENT TALENT 2 2
2 GEORGE STICKS GEORGE STICKS 8 1
3 UNIVERSAL UNIVERSAL 11 0
4 HORIZONS HORIZONS 12 0
5 SYCAMORE SYCAMORE 12 0
6 GOLDEN GUILD GOLDEN GUILD 9 1
7 GOLDEN GUILD GOLDEN GUILD 9 1
8 ACTORS SQUARE ACTORS SQUARE 8 1
9 LAURELS LAURELS 13 0
10 ARTS TALENT ARTS TALENT 10 1
11 FINDERS FINDERS 13 0
12 ALL STARS ALL STARS 12 1
13 ALL STARS ALL STARS 12 1
14 ALL STARS ALL STARS 12 1
15 UNLIMITED UNLIMITED 11 0
16 STARS AND STRIPES STARS AND STRIPES 5 2
17 SETTINGS SETTINGS 12 0
18 STARS AND STRIPES STARS AND STRIPES 5 2
19 UNIVERSAL LIGHTS UNIVERSAL LIGHTS 5 1
20 MODELS AND MAGIC MODELS AND MAGIC 6 2
21 HORIZONS HORIZONS 12 0
22 HARDY STELSON HARDY STELSON 8 1
23 AKA TALENT AKA TALENT 11 1
24 MODELS AND MAGIC MODELS AND MAGIC 6 2
Because you have leading and/or trailing blanks in your input variable. The Strip Function removes them
data test;
a = ' abc ';
ca = countc(a, ' ');
cb = countc(strip(a), ' ');
run;
indeed, so on that basis, results should be identical as in blank variable i used strip function, which removed the leading and trailing blanks. But when i used x variable (x=countc(blank," ");)with countc function, still showing spaces, not in y variable case(y=countc(strip(Agency)," ");)
I'm not sure what you mean by this?
@Naveen1111 wrote:
indeed, so on that basis, results should be identical as in blank variable i used strip function, which removed the leading and trailing blanks. But when i used x variable (x=countc(blank," ");)with countc function, still showing spaces, not in y variable case(y=countc(strip(Agency)," ");)
The variable Blank, when created is the same length as agency. As such it will be padded at the end with blanks.
Example below shows the result of a "stripped" variable sandwiched between : characters. Countc counts them unless explicitly stripped at the time of counting.
data example; x=' Some string with lead and trail blanks '; blank=strip(x); string= ':'||blank||':'; y=countc(string,""); put string=; run;
Look in the log to see value of string.
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.