BookmarkSubscribeRSS Feed
derrickwilliams
Calcite | Level 5

Hello, I'm knew to SAS. I'm trying to understand what the If/else statement is accomplishing in this code.

 

IF dateCommaFinder = 0 THEN

            DO

                date = input(strDate,MMDDYY10.);

                FORMAT date MMDDYY10.;

        day = day(date);

        mnth=month(date);

        year=year(date);

            END;

ELSE

         DO 

              date3 = SUBSTR(strDate, dateCommaFinder+2);

              dateSpaceFinder=INDEX(date3, ' ');

              month = SUBSTR(date3, 1, dateSpaceFinder);

              SELECT (month);

3 REPLIES 3
Kurt_Bremser
Super User

As posted, it causes a syntax error because it is incomplete.

The SELECT statement starts a block that has to be terminated by an END, and the ELSE DO also needs an END.

AMSAS
SAS Super FREQ

It also looks like you are missing semi-colons after both DO statements
You might want to fix your indentation, so that code in a do/end statement is aligned

 

Go check the documentation for examples, and build your code up little by little

 

IF-THEN/ELSE Statement

DO Statement

SELECT Statement

 

IF dateCommaFinder = 0 THEN
  DO ;
    date = input(strDate,MMDDYY10.);
    FORMAT date MMDDYY10.;
    day = day(date);
    mnth=month(date);
    year=year(date);
  END;
ELSE
  DO ;
    date3 = SUBSTR(strDate, dateCommaFinder+2);
    dateSpaceFinder=INDEX(date3, ' ');
    month = SUBSTR(date3, 1, dateSpaceFinder);
    SELECT (month);
      when(<value>)
        do ;
          <some code>
        end ;
        ...
        otherwise        
        do ;
          <some code>
        end ;
      end ;
    end ;
  end ;
ballardw
Super User

You might consider providing some examples of your StrDate variable where the DateCommaFinder is not 0. It is possible that you are doing a lot of string manipulation that is not actually needed but we couldn't tell that without explicit examples.