BookmarkSubscribeRSS Feed
TurnTheBacon
Fluorite | Level 6

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.

4 REPLIES 4
robby_beum
Quartz | Level 8

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;

LinusH
Tourmaline | Level 20

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
Linlin
Lapis Lazuli | Level 10

try:

data want;

  set yourdataset end=last;

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

if not last;

run;

MikeZdeb
Rhodochrosite | Level 12

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 3251 views
  • 11 likes
  • 5 in conversation