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

Hello,

 

Good Evening.

 

I am trying to extract date from a string variable. The variable is called period_desc. It looks like below. I want the date part out of it in mmddyy6. format or any other date format. 

 

period_desc

1 WEEK ENDING 10/28/2017

1 WEEK ENDING 11/04/2017

 


I want just the date part out of it. Here is what I have done so far. i did proc contents to check the type of variables that are being produced and it doesn't seem to be doing the job. P.S I used this code after reading it on this forum but not working for me. 

#VariableTypeLenFormat
4DATENum8MMDDYY10.
3DATE1Char24 
2period_descChar24 
1period_idNum8 

 

Please help!

data period    ;
infile "&input_dir_path.us_period.csv" delimiter = '|' MISSOVER DSD lrecl=32767 firstobs=2 ;
input
             period_id :best12.
             period_desc :$24.
             period_type :$4.
             period_start_date :yymmdd10.
             period_end_date :yymmdd10.
             load_execution_id :best12.
             last_update_datetime :datetime.;
run;

data period_formatted (keep=period_id period_desc DATE1  DATE);
set period;
DATE1 = trim(substr(period_desc,14,11));
DATE = input(DATE1,MMDDYY10.);
format DATE mmddyy10.;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
input period_desc $50.;
cards;
1 WEEK ENDING 10/28/2017
1 WEEK ENDING 11/04/2017
;
data want;
set have;
date=input(scan(period_desc,-1,' '),mmddyy10.);
format date mmddyy10.;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

data have;
input period_desc $50.;
cards;
1 WEEK ENDING 10/28/2017
1 WEEK ENDING 11/04/2017
;
data want;
set have;
date=input(scan(period_desc,-1,' '),mmddyy10.);
format date mmddyy10.;
run;
PaigeMiller
Diamond | Level 26

 i did proc contents to check the type of variables that are being produced and it doesn't seem to be doing the job. 

 

It's not doing the job? You have given us no information about the problem you are experiencing. Explain this. What isn't working? What result do you want that you are not getting? Your PROC CONTENTS shows you have a variable named DATE that is numeric and formatted as a date.

 

Could it be that you really want this?

 

DATE1 = trim(substr(period_desc,15,10));

Or even better yet

 

date1 = scan(period_desc,-1,' ');

 

--
Paige Miller

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