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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.