BookmarkSubscribeRSS Feed
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

Using SAS 9.4

 

How do I change an imported date that should be in date format to date format? SAS imported it as a character.  Thanks

 

 

4 REPLIES 4
TomKari
Onyx | Level 15

Two options: change the code that imports the date value to use the appropriate informat, or keep importing it as character and use the INPUT function to convert it to a number. If you need more specific information, you'll need to post an example. Tom

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

proc import

OUT=mylib.a

DATAFILE=

DBMS=xlsx REPLACE;

SHEET= 'sheet3';

GETNAMES=YES;

RUN;

 

This is my import statement.

 

the variable is second_tx_start_date, what would an input function look like to convert from character to number?

TomKari
Onyx | Level 15

With some file formats, SAS writes the import code to the log, which you can copy and modify. But not with XLSX.

 

So your easiest option is to convert your variable in a subsequent data step, something like this:

 

data work.a_new;
set work.a(rename=(second_tx_start_date = original_second_tx_start_date));
second_tx_start_date = input(original_second_tx_start_date, yymmdd10.);
format second_tx_start_date date.;
drop original_second_tx_start_date;
run;

 

 

You'll need to find the specific informat to use for your date format, the SAS help is the easiest place to look.

 

Tom

Kurt_Bremser
Super User

Problem #1: the Excel file format is not usable for a reliable data transfer. See the Gazillion of posts about it here.

Problem #2: proc import makes guesses, so variable types and other attributes change with the current contents of the infile

 

Save your data to a csv file, import that once with proc import, take the resulting data step from the log and adapt it as needed.

Take control of your process.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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