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

How can i count the spaces in between the words data sp; input word $ 1-100; cards; as,bn hj nm lpo a b acf b c d asdf 29/12, SOUTH TUKOGANJ, run; output                  spacecount as,bn hj nm lpo            4 a b                        1 acf b c d                  3 asdf                      0 29/12, SOUTH TUKOGANJ,    2

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data sp;
input word  $40.;
if countw(word,', ')=5 then flag=1; else flag=0;
cards;
as,bn hj nm lpo
a b
acf b c d
a,b,c,d,e
asdf
29/12, SOUTH TUKOGANJ,
a b,c d e
29/12,29/12,29/12,
;
run;

Ksharp

View solution in original post

4 REPLIES 4
R_Win
Calcite | Level 5

How can i count the spaces in between the words data sp; input word $ 1-100; cards; as,bn hj nm lpo a b acf b c d asdf 29/12, SOUTH TUKOGANJ, run; output                  spacecount as,bn hj nm lpo            4 a b                        1 acf b c d                  3 asdf                      0 29/12, SOUTH TUKOGANJ,    2

Ksharp
Super User
data sp;
input word  $40.;
spacecount=countc(strip(word),' ');
cards;
as,bn hj nm lpo
a b
acf b c d
asdf
29/12, SOUTH TUKOGANJ,
;
run;

Ksharp

Message was edited by: xia keshan

R_Win
Calcite | Level 5

How can i count the spaces in between the words data sp; input word $ 1-100; cards; as,bn hj nm lpo a b acf b c d a,b,c,d,e asdf 29/12, SOUTH TUKOGANJ, a b,c d e 29/12,29/12,29/12, run; Actually i want is in the data if we are having 5 words separated by space or comma it should give one flag as 1 word                    flag as,bn hj nm lpo          1    a b                      0 acf b c d                1 a,b,c,d,e                1 asdf                    0            29/12, SOUTH TUKOGANJ,  0 a b,c d e                1 29/12,29/12,29/12,      0

Ksharp
Super User
data sp;
input word  $40.;
if countw(word,', ')=5 then flag=1; else flag=0;
cards;
as,bn hj nm lpo
a b
acf b c d
a,b,c,d,e
asdf
29/12, SOUTH TUKOGANJ,
a b,c d e
29/12,29/12,29/12,
;
run;

Ksharp

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
  • 4 replies
  • 2216 views
  • 0 likes
  • 2 in conversation