- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 02-27-2009 12:22 AM
(5831 views)
Hi
I have some observations which are like this
data name;
input id$ name$ add$;
cards;
mailtohim nani mainroad
zzzzz zzz street
raju zzzz zzzzzzzzzzzzz
zzzzzzzz zz indi
run;
I have 200 variables in some variables the observations are filled with zzzz and i dont the number of zzzzzz present how can i eliminte and keep space at that place
I have some observations which are like this
data name;
input id$ name$ add$;
cards;
mailtohim nani mainroad
zzzzz zzz street
raju zzzz zzzzzzzzzzzzz
zzzzzzzz zz indi
run;
I have 200 variables in some variables the observations are filled with zzzz and i dont the number of zzzzzz present how can i eliminte and keep space at that place
5 REPLIES 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If I understand your challenge correctly, you can use the SUBSTR function on the left side of the SAS assignment statement in a DATA step. And if you are unsure at what position the string starts, you can use the INDEX function to find the starting offset before using the SUBSTR function to change the value from "zzzzzz" to " " (six blank characters). And, you can use an ARRAY statement to setup a DO loop through your list of 200 SAS variables, so that you do not need to repeat the same code for each variable.
Scott Barry
SBBWorks, Inc.
Scott Barry
SBBWorks, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Or you could use the translate function:
TRANSLATE(source,to-1,from-1<,...to-n,from-n>)
so ....
name=translate(name,' ','z');
I assume you might expect some valid Zs so you might want to code round the function so that it only takes place if there are not non-z characters on either side of the z or something.
Alos, note the confusing way the translate has the TO before the FROM, personally I would have made it the other way round but there you go.
TRANSLATE(source,to-1,from-1<,...to-n,from-n>)
so ....
name=translate(name,' ','z');
I assume you might expect some valid Zs so you might want to code round the function so that it only takes place if there are not non-z characters on either side of the z or something.
Alos, note the confusing way the translate has the TO before the FROM, personally I would have made it the other way round but there you go.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The OP stated clearly that the string to be manipulated represented a "word" -- so possibly TRANWRD may apply.
Scott Barry
SBBWorks, Inc.
Scott Barry
SBBWorks, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
sounds like an ideal case for regular expression handling.
Unfortunately, I can't claim the expertise needed to quickly reply with the code you want. So, Michel_SAS, I recommend you read up on prxchange(). See http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a002601591.htm#a003190494 for an example that might be close to what you seek.
PeterC
Unfortunately, I can't claim the expertise needed to quickly reply with the code you want. So, Michel_SAS, I recommend you read up on prxchange(). See http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a002601591.htm#a003190494 for an example that might be close to what you seek.
PeterC
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think the code below should do the job.
Use the translate version if you want to keep as many blanks as there were 'z' - else use the compress version.
HTH
Patrick
data name;
input id$ name$ add$;
array vars {*} name add;
do i=1 to dim(vars);
if compress(lowcase(vars{i}),'z')='' then
/* vars{i}=translate(lowcase(vars{i}),' ','z');*/
vars{i}=compress(lowcase(vars{i}),'z');
put vars{i}= @;
end;
put;
cards;
mailtohim nani mainroad
zzzzz zzz street
raju zzAzz zzzzzzzzzzzzz
zzzzzzzz zz indi
run;
Use the translate version if you want to keep as many blanks as there were 'z' - else use the compress version.
HTH
Patrick
data name;
input id$ name$ add$;
array vars {*} name add;
do i=1 to dim(vars);
if compress(lowcase(vars{i}),'z')='' then
/* vars{i}=translate(lowcase(vars{i}),' ','z');*/
vars{i}=compress(lowcase(vars{i}),'z');
put vars{i}= @;
end;
put;
cards;
mailtohim nani mainroad
zzzzz zzz street
raju zzAzz zzzzzzzzzzzzz
zzzzzzzz zz indi
run;