- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
try:
data want;
set yourdataset end=last;
newvariable=input(compress(varname),8.);
if not last;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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