Strip function instead of Put statement

Reply
Super Contributor
Posts: 418

Strip function instead of Put statement

I recently realized that when I ran strip on a numeric field (on accident) it actually converted it to character for me, and SAS issued the warning "numeric values have been converted to character at lines :::".

My general question becomes, if you are trying to simply convert variables to characters, wouldn't it just be easier to define them as newvar=strip(oldvar), so you can avoid the informat mess used with the put statement?

I am curious as to the ups / downs of this method and wasn't able to really find any documentation on why put is the 'go to' for this task... And any all comments will be helpful!

Thanks!

Brandon

Respected Advisor
Posts: 3,799

Re: Strip function instead of Put statement

Posted in reply to Anotherdream

Isn't it a NOTE: not a WARNING:?  In PHARMA we like a clean log and that's a dirty note. :smileysilly:

With the automatic conversion there is only one FORMAT choice, with PUT you have options.  You might also look at VVALUE that is conversion with associated FORMAT applied.

Super Contributor
Posts: 418

Re: Strip function instead of Put statement

Posted in reply to data_null__

I'm sorry it is a NOTE: thank you for pointing that out.  And I do understand the idea of the dirty note vs clean log, I guess my point is what if you run into the following circumstance (I just did).

You read in data from a database that does not have an associated format (its numeric length 8).

If I wanted to use a put statement, I can't use a proc contents and grab the informat length (or informat itself) because they would not exist.

Is there a "general" format you can hard-code into your put statements that will work on all numeric data types? I've actually been using Best32 in my macro strings but am not sure if that will ever cause problems (i don't believe it will... but what I don't know about SAS could fill the congressional library).

If I understood your statement above about Vvalue, then I think VValue solves the problem when I want the associated format with the column (and thanks a TON for that, that's actually super helpful as I was not aware of this function).  My question I think makes the most sense with an example.

data balancestest;
   infile datalines delimiter=',';
   format balance dollar32.2;
   input balance $ ;
   datalines;                     
100.35
95
20.62
2362.53
;

data notsure;
set balancestest;
newvar=strip(put(balance,best32.));
run;

In the above code, is it acceptable for me to use best32 (given I don't want the dollar signs in my new character field?).

As always _null_ thank you very much for helping me with questions i'm sure are overly easy.

Brandon

Ask a Question
Discussion stats
  • 2 replies
  • 755 views
  • 0 likes
  • 2 in conversation