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

I have about 30 values in a variable I want to convert from character to numeric.    It seems to work for all but one but I'm not sure why I get an error message on one.

 

27 data a;
28 set Tbl1(keep=e);
29 put e;
30 run;

3015448605
3005949964
3008716173
2510592
3006525584
3012500679
3002806632
1222181
1810189
1940118
1000654629
3011948449
3000718852
1818977
3010477
3000209996
3004708748 
3015448605
1643045
3006316363
3011948449
2518760
1220423
3011286996
3001451441
3005949964
2 The SAS System 11:49 Tuesday, July 13, 2021

1000115571
2246315
1018495
3014937058
NOTE: There were 30 observations read from the data set WORK.TBL1.
NOTE: The data set WORK.A has 30 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

31
32 Data b;
33 set a;
34 b=input(e,11.);
35 run;

NOTE: Invalid argument to function INPUT at line 34 column 4.
E=3004708748  b=. _ERROR_=1 _N_=17
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 34:4
NOTE: There were 30 observations read from the data set WORK.A.
NOTE: The data set WORK.B has 30 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The last character in that invalid string is 'A0'x, not '20'x (space).

Try removing it before trying to interpret it as a number.

b=input(compress(e,'A0'x),32.);

View solution in original post

2 REPLIES 2
Astounding
PROC Star

Notice the NOTE you get.

 

After b=., there is a single blank.

 

After _ERROR_=1, there is a single blank.

 

But after E=3004708748, it looks like you have two blanks.  Actually, the first of those is not a blank.  It is some unprintable character, such as a tab character.  It looks like a blank, but it's not, and whatever it is it needs to be removed.

Tom
Super User Tom
Super User

The last character in that invalid string is 'A0'x, not '20'x (space).

Try removing it before trying to interpret it as a number.

b=input(compress(e,'A0'x),32.);

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 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
  • 2 replies
  • 536 views
  • 2 likes
  • 3 in conversation