SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to convert Character variables w/spaces into Numeric ones, in DI Studio?

Reply
Frequent Contributor
Posts: 89

How to convert Character variables w/spaces into Numeric ones, in DI Studio?

If I have a character variable with the value "45 000" and want to turn it into a numeric variable, the space is obviously going to cause a problem. Can you please tell me how I can edit my expression to resolve this?

          input(varname, 8.0)

Incidentally, can you also please advise on how I can make my data step exclude the last row from the data set? The total number of rows will change from month to month.

Thanks.

Contributor
Posts: 73

Re: How to convert Character variables w/spaces into Numeric ones, in DI Studio?

Posted in reply to TurnTheBacon

For the first part of your question...I'm not familiar with DI Studio but this works in EG 4.3...maybe it'll help:

DATA grades;
   input idno 1-2 variable $ 5-11;
   cards;
01  45 000
02  32 000
03  100 000
;
RUN;

data grades_1(keep=idno variable2);
   set grades;

   variable1=CATS(SCAN(variable,1), SCAN(variable,2));
   variable2=INPUT(variable1, best.);
run;

PROC PRINT data = grades_1 NOOBS;
   title 'The grades data set';
RUN;

Super User
Posts: 5,438

Re: How to convert Character variables w/spaces into Numeric ones, in DI Studio?

Posted in reply to TurnTheBacon

As for the last row, I think the simplest is to have a data step in a user written transform, in which you specify if end=last then delete; or something similar.

The comma informat should do the trick.

Data never sleeps
Super Contributor
Posts: 1,636

Re: How to convert Character variables w/spaces into Numeric ones, in DI Studio?

Posted in reply to TurnTheBacon

try:

data want;

  set yourdataset end=last;

newvariable=input(compress(varname),8.);

if not last;

run;

Valued Guide
Posts: 765

Re: How to convert Character variables w/spaces into Numeric ones, in DI Studio?

Posted in reply to TurnTheBacon

hi ... the COMMA informat removes internal blanks ...

data grades;

input x $20.;

datalines;

45 000

32   000

1 2 3 4 5

1       0

100 000

;

data grades;

set grades end=last;

y = input(x,comma20.);

if ^last;

run;

   x            y

45 000       45000

32   000     32000

1 2 3 4 5    12345

1       0       10

Ask a Question
Discussion stats
  • 4 replies
  • 1019 views
  • 11 likes
  • 5 in conversation