DATA Step, Macro, Functions and more

Data appears as Char rather than num

Accepted Solution Solved
Reply
Super Contributor
Posts: 328
Accepted Solution

Data appears as Char rather than num

[ Edited ]

 

Hello, I have the date below coming up as "char" , 15, $15, $15 but I want it to be "num", 8, Datetime , anydtdtm40.

 
 

 

 

Obs BP_Rd_Time
1  
2 2/9/2017 13:44
3  
4 2/8/2017 13:20
5  
6 2/8/2017 14:45
7  
8 2/8/2017 8:00
9 2/16/2017 19:31
10  
11  
12  
13 2/21/2017 2:45
14 2/6/2017 22:15
15  

Accepted Solutions
Solution
a month ago
Respected Advisor
Posts: 3,054

Re: Data appears as Char rather than numeriv

Posted in reply to desireatem

If these are truly character and not numeric, you can turn them into numerics via the INPUT function, using one of these informats: ANYDTDTEw. ANYDTDTMw. ANYDTTMEw.

--
Paige Miller

View solution in original post


All Replies
Solution
a month ago
Respected Advisor
Posts: 3,054

Re: Data appears as Char rather than numeriv

Posted in reply to desireatem

If these are truly character and not numeric, you can turn them into numerics via the INPUT function, using one of these informats: ANYDTDTEw. ANYDTDTMw. ANYDTTMEw.

--
Paige Miller
Super Contributor
Posts: 328

Re: Data appears as Char rather than numeriv

[ Edited ]
Posted in reply to PaigeMiller

I do not understand.

 

1573 data firstobs;
1574 set firstobs;
1575 BP_Time=input(BP_Rd_Time, ANYDTDTEw.);
----------
48
ERROR 48-59: The informat ANYDTDTEW was not found or could not be loaded.

1576 run;

NOTE: Numeric values have been converted to character values at the places given by:
(Line)Smiley SadColumn).
1575:9 1575:15
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FIRSTOBS may be incomplete. When this step was stopped there were
0 observations and 64 variables.
WARNING: Data set WORK.FIRSTOBS was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

Super User
Posts: 23,771

Re: Data appears as Char rather than numeriv

[ Edited ]
Posted in reply to desireatem

See the approach outlined here:

https://communities.sas.com/t5/Base-SAS-Programming/date-manupulation/m-p/383548

 

It's a variant on the same question where you need to convert a character to a date format. 

If you can't get it working, post your code and we're happy to help. 

 


@desireatem wrote:

I do not understand.

 

1573 data firstobs;
1574 set firstobs;
1575 BP_Time=input(BP_Rd_Time, ANYDTDTEw.);
----------
48
ERROR 48-59: The informat ANYDTDTEW was not found or could not be loaded.

1576 run;

NOTE: Numeric values have been converted to character values at the places given by:
(Line)Smiley SadColumn).
1575:9 1575:15
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FIRSTOBS may be incomplete. When this step was stopped there were
0 observations and 64 variables.
WARNING: Data set WORK.FIRSTOBS was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds


 

Super User
Posts: 23,771

Re: Data appears as Char rather than numeriv

[ Edited ]
Posted in reply to desireatem

 Don't code like this, having the same name in your DATA and SET statement. Look slightly further down and notice the warning. You've now destroyed your input data set and now need to recreate it.

 

1573 data firstobs;
1574 set firstobs;

 

...

 

WARNING: The data set WORK.FIRSTOBS may be incomplete. When this step was stopped there were
0 observations and 64 variables.

 

EDIT: w in the informat is for the width, the docs show it as a number. Either remove it or add a number in its place to indicate the width of the informat.

Super Contributor
Posts: 328

Re: Data appears as Char rather than numeriv

Same error message;

 

1581 data firstobs10;
1582 set firstobs;
1583 BP_Time=input(BP_Rd_Time, ANYDTDTEw.);
----------
48
ERROR 48-59: The informat ANYDTDTEW was not found or could not be loaded.

1584 run;

NOTE: Numeric values have been converted to character values at the places given by:
(Line)Smiley SadColumn).
1583:9 1583:15
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FIRSTOBS10 may be incomplete. When this step was stopped there
were 0 observations and 64 variables.
WARNING: Data set WORK.FIRSTOBS10 was not replaced because this step was stopped.

Super User
Posts: 10,278

Re: Data appears as Char rather than numeriv

Posted in reply to desireatem

The lowercase w is just used as a placeholder for the length of the informat.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Posts: 328

Re: Data appears as Char rather than numeriv

Posted in reply to PaigeMiller

Thanks, this is correct:

 

data firstobs10;
set firstobs2;
BP_Time=input(BP_Rd_Time, ANYDTDTM40.);
run;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 97 views
  • 0 likes
  • 4 in conversation