Help using Base SAS procedures

when the character variable contains different formats then how to convert that into numeric

Reply
Frequent Contributor
Posts: 111

when the character variable contains different formats then how to convert that into numeric

Hi all,
can any one know the format for this
i have the dataset like this

product amount
account value
fixed 1,52,132
variable 2,50,478
annual rate
product 4.5%
variable 5.6%
this over all is one dataset.
i have read this data from excel using libname statement.
and the variable amount is in character type.
now i have to convert the data i.e. amount into numeric.
can any one know the process please comment.

Super User
Posts: 11,343

Re: when the character variable contains different formats then how to convert that into numeric

Posted in reply to Ravikumarkummari

Is all of this in one column (variable) in the SAS data set? If so this is likely to be a mess. SAS can only have one characteristic per variable, either numeric or character. So you will have to create new variables using a data step. You may need to provide a bit more data for input example AND an example of what the output should look like.

It looks like you actually have 3 values for the rows that start with Fixed and Variable, is that the actual case? or did we lose something in pasting into the forum?

Super User
Posts: 7,854

Re: when the character variable contains different formats then how to convert that into numeric

Posted in reply to Ravikumarkummari

Read the column into a char variable, then check that variable for its layout and select the proper conversion.

It would be nice if you could provide an example of the data in csv form, so that we can determine the actual positioning of the data in the cells.

(ie is "product amount" in one or 2 cells?)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,988

Re: when the character variable contains different formats then how to convert that into numeric

Posted in reply to Ravikumarkummari

Am linking this thread: https://communities.sas.com/thread/75128

Here, as its exactly the same question.

Super User
Posts: 10,044

Re: when the character variable contains different formats then how to convert that into numeric

Posted in reply to Ravikumarkummari
data have;
input p $ a : $20.;
cards;
fixed 1,52,132
variable 2,50,478
product 4.5%
variable 5.6%
;
run;
data want;
 set have;
 length fmt $ 20;
 if findc(a,',') then fmt='comma32.';
  else if findc(a,'%') then fmt='percent12.';
   else fmt='best32.';
 v=inputn(a,fmt);
 run;

Xia Keshan

Ask a Question
Discussion stats
  • 4 replies
  • 250 views
  • 0 likes
  • 5 in conversation