hi i have the following data
CRit
-currrent or prior tre
-prior use of treat
i am trying to get rid of '-' hypen at starting of each value.
could any one please help me out to remove that.
Sure
data test;
string = "-minus";
new_string = translate(string,"","-");
run;
.
Sure
data test;
string = "-minus";
new_string = translate(string,"","-");
run;
.
Thanks Tilea. That worked perfectly.
However it worked but in my values there are '-' in middle too those are removing too.
so i just need to remove only the first position of value only For '-'.
data have;
input v$;
cards;
abc
-bc
a-b
;
data want;
set have;
v=ifc(first(v)='-',compress(v,'-'),v);
proc print;run;
You are right.
It is the same as
if first(v)='-' then v=compress(v,'-');
Thanks Lin lin. but when I have "-" in the middle its getting removed too. For instance in the following example for the third value "-a-b" have "-" at the begining and the middle also.
data have;
input v$;
cards;
abc
-bc
-a-b
;
When I tried the following code,
if first(v)='-' then v=compress(v,'-');
My output is :
abc
bc
ab
but the required output is (i.e If there is any "_" in the middle other than first position I need to keep it as is)
abc
bc
a-b
Please help.
sorry!
try this one.
data have;
input v$;
cards;
abcc
-bcc
-a-b
;
data want;
set have;
v=ifc(first(v)='-',substr(v,2),v);
proc print;run;
Obs v
1 abcc
2 bcc
3 a-b
How about this:
data have;
input v$;
cards;
abc
-bc
-a-b
;
data want;
set have;
v1= prxchange("s/-//i",1,strip(v));
run;
Hi Linlin and Tilea,
Thank both of you for your help. I really appreciate your input.
Could you please help me with the following one too.
Data sample:
Set sample;
Amd1_9-;
AMD1_10-;
Run;
AMD1_9-History of another malignancy within the previous 5 years other than curatively treated non-
melanomatous skin cancer
AMD1_10-Current or prior treatment with estrogens and/or drugs with anti-androgenic properties such
as spironolactone > 50mg/kg, or progestational agents for the treatment of prostate cancer less than 6
months prior to randomization .
In my variable sample I have two sets of values one is 7 char in length second set is 8 char in length
I need to just remove up to colon part and my variable should be starting from alphabets.
Can u Please help me out.
Which Colon part?
What do you need?
This is what you have for a variable named sample it takes values amd1_9- and amd1_10-
Sample
Amd1_9-
AMD1_10-
And you want an new variable new_sample to take what values exactly:
New_Sample
?
?
You have a variable called sample like this
Sample
Amd1_9-
AMD1_10-
Could you please be more specific what do you need the new variable to look like:
Sample
?
?
And for the other problem with removing the string, why do you need more ways?
what's wrong with what either I or LinLin offered?
data have;
input string$;
cards;
abc
-bc
-a-b
;
data want;
set have;
string1= prxchange("s/-//i",1,strip(string));
run;
should work....
Hi,
Please try to use compress(variable,'-'); check the sample code
data want;
set have;
newvar=compress(variable,'-');
run;
This code will remove the '-' hyphen from the variable.
Thanks,
Jagadish
How about
if string =: '-' then string = substr(string,2);
won't remove anything except a "-" from the first position.
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.