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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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