Hi i have values like 10( 92.9),12( 1.0), 15( 100),14( 87.7) i have to remove only one leading spaces from each i am using 5.1 format if i use 4.1 i am getting W.D note in log. output like 10(92.9),12( 1.0),15(100),14(87.7).
Thank you.
Are these values numeric or character? What numeric value does 15( 100.0) represent?
@Vijay77 , the best approach would be to use the picture format on the percentage separately which creates the character percentage and then concatenate the count with character percentage as i showed in my earlier post.
Try this
data have;
input value $9.;
datalines;
10( 92.9)
12( 1.0)
15( 100)
14( 87.7)
;
data want(drop=a i);
set have;
do i=1 to length(value);
a=char(value, i);
if a=' ' then do;
newvalue=cat(substr(value, 1, i-1), substr(value, i+1, length(value)));
leave;
end;
end;
run;
Please try the picture format as below
proc format;
picture val (default=8)
low-9.9='009.9)' (prefix='( ')
10-99.9='009.9)' (prefix='( ')
100-high='009.9)' (prefix='(');
run;
data want;
input cnt pct;
new=cats(put(cnt,best.),put(pct,val.));
cards;
10 92.9
12 1.0
15 100
14 87.7
;
proc print;
run;
Can't a COMPRESS( ) function simplify the solution for dropping a SPACE?
data need;
set have;
value = compress(value);
run;
@KachiM wrote:
Can't a COMPRESS( ) function simplify the solution for dropping a SPACE?
data need; set have; value = compress(value); run;
No, since it removes ALL of the spaces.
More likely they just want to change some of them. perhaps like this:
value = tranwrd(value,'( ','( ');
@Vijay77 wrote:
Hi i have values like 10( 92.9),12( 1.0), 15( 100),14( 87.7) i have to remove only one leading spaces from each i am using 5.1 format if i use 4.1 i am getting W.D note in log. output like 10(92.9),12( 1.0),15(100),14(87.7).
Thank you.
Show the code you used to create these strings.
@Vijay77 wrote:
Hi i have values like 10( 92.9),12( 1.0), 15( 100),14( 87.7) i have to remove only one leading spaces from each i am using 5.1 format if i use 4.1 i am getting W.D note in log. output like 10(92.9),12( 1.0),15(100),14(87.7).
Thank you.
Please post the data you have before creating those strings. If the strings are the result of concatenating numbers, i am sure that creating multiple blanks can be avoided.
@Vijay77 wrote:
Hi i have values like 10( 92.9),12( 1.0), 15( 100),14( 87.7) i have to remove only one leading spaces from each i am using 5.1 format if i use 4.1 i am getting W.D note in log. output like 10(92.9),12( 1.0),15(100),14(87.7).
Thank you.
If you are using a PUT function somewhere you might want to consider using the -L alignment operator consider:
data example; x = 37.5; length string1 string2 $ 10; string1= catt('(',put(x,5.1),')'); string2= catt('(',put(x,5.1 -L),')'); run;
String1 will have the leading space, String2 does not.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.