SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1624 views
  • 1 like
  • 2 in conversation