BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Deep_Impact
Calcite | Level 5
data VITALS.vitals_1;
set VITALS.vitals_new;
CodeChar=put(code, datetime16.);
run;

Hi All,

 

I have a character variable "Code" in CSV file (eg : 123456-1) which gets automatically converted to DATETIME16. numeric format ( Informat : ANYDTDTM40.;  eg 01JUN80:00:00:00) when I try importing the file. 

 

Please suggest me ways to prevent it while importing or how to convert back the numeric DATETIME16. variable in the imported SAS file to the original $9 character variable. 

 

I am using  the following code to convert a DATETIME16. numeric format like 01JUN80:00:00:00 to get $9 character format like 8430-6)

 

data VITALS.vitals_1;
set VITALS.vitals_new;
CodeChar=put(code, datetime16.);

*/ "Code" is the numeric DATETIME16. variable which should needs be in character format like 8430-6 */;
run;

 

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
It takes longer but should definitely stop. Once you have working code, take that from the log and run that next time. It's significantly faster because it can avoid the step of figuring out the data types.

View solution in original post

3 REPLIES 3
Reeza
Super User

Welcome to the SAS Community forums. 

 

For this type of errors you should fix it in the IMPORT process, not after the fact because you cannot assume that SAS parsed it correctly at all. 

 

I'm assuming you used PROC IMPORT or an IMPORT task to import the data? If so, check the log after, it will have the full code that was used. Take that code and modify the FORMAT/INFORMAT and INPUT statement for the variable in question. Change the format/informat to $9 instead. If you only have a few variables it may be easier to write a data step import yourself. 

 

Another option is to add the GUESSINGROWS=MAX to your code to see if it fixes itself but it may not.

 

proc import out=vitals.vitals_new datafile="path to file" dbms=csv replace;
guessingrows=max;
run;

@Deep_Impact wrote:
data VITALS.vitals_1;
set VITALS.vitals_new;
CodeChar=put(code, datetime16.);
run;

Hi All,

 

I have a character variable "Code" in CSV file (eg : 123456-1) which gets automatically converted to DATETIME16. numeric format ( Informat : ANYDTDTM40.;  eg 01JUN80:00:00:00) when I try importing the file. 

 

Please suggest me ways to prevent it while importing or how to convert back the numeric DATETIME16. variable in the imported SAS file to the original $9 character variable. 

 

I am using  the following code to convert a DATETIME16. numeric format like 01JUN80:00:00:00 to get $9 character format like 8430-6)

 

data VITALS.vitals_1;
set VITALS.vitals_new;
CodeChar=put(code, datetime16.);

*/ "Code" is the numeric DATETIME16. variable which should needs be in character format like 8430-6 */;
run;

 

 

Thanks


 

Deep_Impact
Calcite | Level 5

@Reeza : Thanks for your help; the guessingrows options worked in the proc import stage when I put a number like 100000. The guessingrows=max option was not allowing the datastep to stop. 

Reeza
Super User
It takes longer but should definitely stop. Once you have working code, take that from the log and run that next time. It's significantly faster because it can avoid the step of figuring out the data types.

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 16. 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
  • 3 replies
  • 1182 views
  • 1 like
  • 2 in conversation