- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data work.cities;
input city $char15.;
datalines;
New York
Los Angeles
Las Vegas
San Diego
;
run;
How to remove leading blanks
left function cannot accomplish this task
compress and strip both remove leading and trailling
i want to remove only leading blanks from string
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data work.cities;
input city $char15.;
want=prxchange('s/^\s+//',1,city);
datalines;
New York
Los Angeles
Las Vegas
San Diego
xxxxxxxxx
;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please describe exactly how "left function cannot accomplish this task".
And perhaps do you mean more that just leading blanks? If you mean the extra spaces in the middle of "
San Diego
those would not be "leading blanks".
You also do not understand that "trailing blanks" are only of concern at certain uses. SAS character variables that are not defined the the full length of a variable will have "trailing blanks" only for some operations. Always.
@BrahmanandaRao wrote:
data work.cities; input city $char15.; datalines; New York Los Angeles Las Vegas San Diego ; run;
How to remove leading blanks
left function cannot accomplish this task
compress and strip both remove leading and trailling
i want to remove only leading blanks from string
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Left function can does left allignment only it can not any string manuplations
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@BrahmanandaRao wrote:
Left function can does left allignment only it can not any string manuplations
Suggest that you try this code and see if that matches what you say above.
data work.cities; input city $char15.; city=left(city); datalines; New York Los Angeles Las Vegas San Diego ; run;
There are places in REPORT functions where Left is a justification and does not change the actual value. But the Function Left does just fine for removing spaces at the beginning of a string. If you have characters that don't visibly print and are not spaces, such as Tab or ASCII 255, it may appear as though the "space" was not removed because the actual character was not in fact a space.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The $char informats are designed to preserve leading blanks. If you don't want leading blanks, switch to:
input city $15.;
Note that any solution you use wlll leave CITY with a length of $15. So any leading blanks that are removed will become trailing blanks instead, to reach that length of $15,.
It's not clear if you want to change multiple embedded blanks. For example, do you want to end up with
"San Diego" vs. "San Diego"
If that is the issue, apply the COMPBL function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @BrahmanandaRao,
As you have done with the input data, please supply another data step with datalines that show what output data you want based on the input data you have provided.
Based on the responses you've had so far, showing your desired output should help clarify your requirements.
To "remove leading blanks" (as per your subject title), you can look at the left() function definition and example in the documentation to see if it should give you what you want.
Kind regards,
Amir.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I assume that you both want to get rid of the leading blanks and reduce the multiple blanks inside the names to single blanks.
For the first thing, use LEFT. For the next thing, use COMPBL, e.g.:
city=left(compbl(city));