DATA Step, Macro, Functions and more

how to capture character variable data containing space

Accepted Solution Solved
Reply
Contributor
Posts: 63
Accepted Solution

how to capture character variable data containing space

Hi,

In the attached sheet, I want to read the data into SAS environment and then find all country id with extra space in the beginning or middle.

 

How to proceed. My output would be country id 222, 223 and 226

 

 


Accepted Solutions
Solution
‎10-26-2017 02:19 AM
Super User
Posts: 10,530

Re: how to capture character variable data containing space

[ Edited ]

Why do you want to have 226 included? There's no blank at the beginning or in the middle, only at the end.

Checking a SAS character variable for trailing blanks makes no sense, as _all_ SAS character variables have trailing blanks (unless they're completely filled). "Empty" character variables contain blanks.

 

To find the others, you might want to check

if indexc(trim(countryname),' ') > 0;

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
‎10-26-2017 02:19 AM
Super User
Posts: 10,530

Re: how to capture character variable data containing space

[ Edited ]

Why do you want to have 226 included? There's no blank at the beginning or in the middle, only at the end.

Checking a SAS character variable for trailing blanks makes no sense, as _all_ SAS character variables have trailing blanks (unless they're completely filled). "Empty" character variables contain blanks.

 

To find the others, you might want to check

if indexc(trim(countryname),' ') > 0;

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 98 views
  • 0 likes
  • 2 in conversation