DATA Step, Macro, Functions and more

Problem using Input to convert char with missing values to num

Accepted Solution Solved
Reply
Contributor
Posts: 57
Accepted Solution

Problem using Input to convert char with missing values to num


Hi,

first of all, wish everyone happy new year Smiley Happy I am hoping to improve my sas knowlege in 2014 and here goes the new question.

I want to convert a char variable names 'Wert' to a num variable. It contains only natural numbers and missing values, but saved as a char as a result of a proc transpose procedure. There are a lot of suggestions in the internet how to do it.

I first tried this solution:


data korr.have_num;

set korr.have;

Values=Wert*1;

Format Values COMMAX32.;

RUN;

The problem is that I am using the num format COMMAXw. (as normally in Germany) which means period separates every three digits and a comma separates the decimal fraction. (so 30.000 doesnt equal to 30). The statement 'Format Values COMMAX32.' only specifies the format for the new variable Values but when SAS did the muplication, it still uses Commaw. format. So I got from 18.987 19, which isnt what i want.

Another solution war to use the input function. I tried like this:

datat korr.have_num;

set korr.have;

values=input(Wert, Commax32.);

run;

After this data step, the variable values has only missing values, which i dont understand why.

Can someone help me solving this problem?

many thanks.  Dingdang


Accepted Solutions
Solution
‎01-03-2014 09:06 AM
Super Contributor
Posts: 339

Re: Problem using Input to convert char with missing values to num

building upon appropriate input is typically better than the first solution as multiplying char by numeric issues a warning in the log and those should be avoided for any large process.

could you provide a datalines example with data that does not get input properly by solution #2? Odds are you can apply some simple string function to WERT inside the input function to make it inputable appropriately. Likely strip to remove blanks or possibly the same solution you've mentionned using an alternative input format after removal of periods.

View solution in original post


All Replies
Contributor
Posts: 57

Re: Problem using Input to convert char with missing values to num

ok, I read some old posts und used at first the compress function to get the '.' out of the numbers and then used the first solution, and it worked well.

But i am still interested in knowing, where the problem with Input comes from.

BR  Dingdang

Solution
‎01-03-2014 09:06 AM
Super Contributor
Posts: 339

Re: Problem using Input to convert char with missing values to num

building upon appropriate input is typically better than the first solution as multiplying char by numeric issues a warning in the log and those should be avoided for any large process.

could you provide a datalines example with data that does not get input properly by solution #2? Odds are you can apply some simple string function to WERT inside the input function to make it inputable appropriately. Likely strip to remove blanks or possibly the same solution you've mentionned using an alternative input format after removal of periods.

Frequent Contributor
Posts: 89

Re: Problem using Input to convert char with missing values to num

data EEN;

input var1 $  var2:$10. ;

  datalines;

  100.66  100.255,77

  ;

run;

data TWEE;

   set EEN;

 

V1=input(var1,15.);

V2=input(var2,commax15.2);

   format V1-V2 commax10. ;

 

run;

proc print;

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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