BookmarkSubscribeRSS Feed
Vijay77
Fluorite | Level 6

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. 

12 REPLIES 12
Vijay77
Fluorite | Level 6
its 15( 100.0) not 15( 100).
PeterClemmensen
Tourmaline | Level 20

Are these values numeric or character? What numeric value does 15( 100.0) represent?

Vijay77
Fluorite | Level 6
all values are charcter
Jagadishkatam
Amethyst | Level 16

@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.

Thanks,
Jag
PeterClemmensen
Tourmaline | Level 20

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;
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag
KachiM
Rhodochrosite | Level 12

Can't a COMPRESS( ) function simplify the solution for dropping a SPACE?

data need;
   set have;
   value = compress(value);
run;
Tom
Super User Tom
Super User

@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,'(  ','( ');
data_null__
Jade | Level 19

@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.  

andreas_lds
Jade | Level 19

@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.

ballardw
Super User

@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.

Astounding
PROC Star
V = cat( scan(v, 1, '('), '(', scan(v, 2, ' ' ) ) ;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 12 replies
  • 2986 views
  • 0 likes
  • 9 in conversation