BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bncoxuk
Obsidian | Level 7

Hello Smiley Happy

I have a numeric variable x with values ranging from 1, 2 to 25. If I simply use: y = PUT(x,  2.) then there will be one blank space for those x with one single digit, because the PUT function makes the length of 2 for all y.

My question is: how can I make this conversion without adding any blanks to y?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

If you were outputting the data to a text file, I'd suggest using the -l modifier.  However, if you simply want to remove the extra spaces in the data itself, you could always just "strip" them.  e.g.,

data test;

  set sashelp.class;

  if _n_ lt 6 then age=_n_;

  age1char=put(age,2.);

  age2char=strip(put(age,2.));

  x=length(age1char);

  y=length(age2char);

run;

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

If you were outputting the data to a text file, I'd suggest using the -l modifier.  However, if you simply want to remove the extra spaces in the data itself, you could always just "strip" them.  e.g.,

data test;

  set sashelp.class;

  if _n_ lt 6 then age=_n_;

  age1char=put(age,2.);

  age2char=strip(put(age,2.));

  x=length(age1char);

  y=length(age2char);

run;

data_null__
Jade | Level 19

You could also use -L with the PUT function.  PUT(AGE,2.-L)

art297
Opal | Level 21

DN, Totally agree!  But, I think it is really just a matter of preference as there is virtually NO performance difference between the two methods (at least when tested on 1.9 million records).

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 831 views
  • 0 likes
  • 3 in conversation