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

I've got a data set where, for one reason or another, one of the date variables is coming in as a character variable. Missing variables are blank, dates are present as things like 01-Nov-08. I need these in the proper SAS days-since-1/1/1960 format.

I've tried using %sysfunc, but I can't seem to get it to cooperate. Any chance someone can point me in the right direction?

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You can use function input to get that.

num_date=input(char_date,date12.);

format num_date mmddyy12.;

Ksharp

View solution in original post

4 REPLIES 4
Ksharp
Super User

You can use function input to get that.

num_date=input(char_date,date12.);

format num_date mmddyy12.;

Ksharp

andy_wk
Calcite | Level 5

Hi Ksharp,

Is it the only way to do?

Cheers.

ballardw
Super User

You don't say how you are reading the data but when you indicate " for one reason or another, one of the date variables is coming in as a character variable" I suspect proc import.

Proc Import uses lots of defaults and limited information from the source data. You might be able to write a datastep to read the data source and apply an informat at that time, but without details of the source data this is a guess.

Ksharp
Super User

What do you mean ?

proc format;

invalue $fmt

'Nov'=11

'Dec'=12

.........

;

run;

num_date=mdy(

input(scan(char_date,'-',2),$fmt.),

input(scan(char_date,'-',1),best8.),

input(scan(char_date,'-',-1),best8.);


sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1021 views
  • 0 likes
  • 4 in conversation