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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
DBailey
Lapis Lazuli | Level 10

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

6 REPLIES 6
Reeza
Super User

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.

nickb
Calcite | Level 5

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.

ballardw
Super User

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.

DBailey
Lapis Lazuli | Level 10

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;

Astounding
PROC Star

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

,mmddyy8.)

with this:

,??mmddyy8.)

ballardw
Super User

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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 1662 views
  • 0 likes
  • 5 in conversation