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

All,

I have created table 'duedatepop1' that contains 3 variables (case_identifier, duedatepop, and note).  Note variable is one of two results:

Due Date changed from [empty] to [2020-03-01 00:00:00]

-OR-

Due Date changed from [11/23/2019 12:00 AM] to [2020-04-27 00:00:00]

 

I am needing to parse the date from the second set of brackets into a new table with the same variables in addition to the new date field (duedate), but I've not been able to do so.  I'm not sure if the brackets are causing an issue or not.  Thanks in advance for any and all assistance rendered.  

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I am interpreting this as that you have SAS data set with a character variable holding text as shown.

If, and this a moderately big if , all the text has exactly two sets of values inside [] and at least one word or space between them the following may help:

data example;
   x ="Due Date changed from [11/23/2019 12:00 AM] to [2020-04-27 00:00:00]";

   date = input( scan (x,4,'[]'),yymmdd10.);
   format date date9.;
run;

I am assuming that you wanted an actual SAS date value and use the DATE9 format just to show the date is such. Pick your own format.

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

What code you tried ? and what issues you had?

Please post

(1) a sample of data

(2) the full log (code + messages) of your run

(3) show what result you expect.

ballardw
Super User

I am interpreting this as that you have SAS data set with a character variable holding text as shown.

If, and this a moderately big if , all the text has exactly two sets of values inside [] and at least one word or space between them the following may help:

data example;
   x ="Due Date changed from [11/23/2019 12:00 AM] to [2020-04-27 00:00:00]";

   date = input( scan (x,4,'[]'),yymmdd10.);
   format date date9.;
run;

I am assuming that you wanted an actual SAS date value and use the DATE9 format just to show the date is such. Pick your own format.

hnb_matt_d
Obsidian | Level 7

Minor adjustment, but it worked!  

 

data duedatepop2;
set work.duedatepop1;
duedate = input(scan(note,4,'[]'),yymmdd10.);
format duedate date9.;
drop note;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1631 views
  • 1 like
  • 3 in conversation