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

Please advise how to readin following week date.

Data Test;
input weekdate ; 
format weekdate	DTWKDATX25.;  
datalines; 
Saturday, March 31, 2018
Monday April 2, 2018
;
Run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You need to remove the redundant weekday first with substr(), then anydtdte will recognize the date:

data test;
input datestr $30.;
i = index(datestr,' ');
date = input(substr(datestr,i),anydtdte30.);
drop i;
format date weekdate30.;
cards;
Saturday March 31, 2018
;
run;

 

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

You only have dates, so a datetime format won't work.

 

The anydtdte informat can read a written (US style) date:

data test;
input date anydtdte30.;
format date yymmddd10.;
cards;
march 31,2018
;
run;

You need to remove the weekday first.

emrancaan
Obsidian | Level 7

Hi Kurt,

 

I want to read Saturday March 31, 2018 and store it in date type variable as it is.

 

Kurt_Bremser
Super User

You need to remove the redundant weekday first with substr(), then anydtdte will recognize the date:

data test;
input datestr $30.;
i = index(datestr,' ');
date = input(substr(datestr,i),anydtdte30.);
drop i;
format date weekdate30.;
cards;
Saturday March 31, 2018
;
run;

 

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