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


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

1 ACCEPTED SOLUTION

Accepted Solutions
Vince28_Statcan
Quartz | Level 8

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

3 REPLIES 3
Dingdang
Fluorite | Level 6

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

Vince28_Statcan
Quartz | Level 8

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.

Jaheuk
Obsidian | Level 7

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 3554 views
  • 0 likes
  • 3 in conversation