Help using Base SAS procedures

Checking date

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

Checking date

I'm trying to use an IF statement to check and see if the value I want is in the date format MMDDYY8. and if so do.....

Data:

      ENG-112 ENGLISH COMPOSITION II..... 06/30/03 CR  1.5  *TE
      ENG-113 ENGLISH COMPOSITION III.... 06/30/03 CR  1.5  *TE

IF statement:

IF index(row, '-')= 14 and ANYDIGIT(row)= 15  and substr(row,findc(row, '/')-2,8)= "MMDDYY8.d"  then

do

     ....

end;


Accepted Solutions
Solution
‎01-24-2013 01:10 PM
Super Contributor
Posts: 578

Re: Checking date

I guess you could hard code it:

data work.have;

length row $100.;

input @1 row $Char69.;

if substr(row,14,1)='-'  and input(substr(row,47,8),mmddyy8.) ne . ;

cards;

           ENG-112 ENGLISH COMPOSITION II..... 06/30/03 CR   1.5  *TE

           ENG-113 ENGLISH COMPOSITION III.... 06/30/03 CR   1.5  *TE

;

run;

View solution in original post


All Replies
Super User
Posts: 17,819

Re: Checking date

Is your data one long string or are you trying to figure out how to parse it? I would parse it as text and then deal with it separately, you can try anydtdte format as well as an informat.

Contributor
Posts: 65

Re: Checking date

It is one long string.  I plan on parsing it but i need the IF statement to check and make sure I want the values.

Super User
Posts: 10,500

Re: Checking date

You may want something like:

  pos = prxmatch('/\d{2}\/\d{2}\/\d{2} /',x);

X is the name of the variable to search the string.

Pos here is the position that a dd\dd\dd<space> string is found in X

You need to have the final space as otherwise dd\dd\dddd would not be differentiated.

Solution
‎01-24-2013 01:10 PM
Super Contributor
Posts: 578

Re: Checking date

I guess you could hard code it:

data work.have;

length row $100.;

input @1 row $Char69.;

if substr(row,14,1)='-'  and input(substr(row,47,8),mmddyy8.) ne . ;

cards;

           ENG-112 ENGLISH COMPOSITION II..... 06/30/03 CR   1.5  *TE

           ENG-113 ENGLISH COMPOSITION III.... 06/30/03 CR   1.5  *TE

;

run;

Super User
Posts: 5,081

Re: Checking date

To avoid getting messages about invalid data, you might want to replace this:

,mmddyy8.)

with this:

,??mmddyy8.)

Super User
Posts: 10,500

Re: Checking date

Test this version with a line of data containing 06/10/2003 and see what happens. This was my first approach to the logic.

It will treat it as a valid date of 6/10/1920 (assuming your year cutoff date is the same as my default).

If you never have mm/dd/yyyy data no problem.

Also, if the date is invalid such as 02/30/03 it will also be missing. So you may need to check further.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 289 views
  • 0 likes
  • 5 in conversation