Search code examples
sasprompt

Type of date as prompt


I have standard routine for PROMPT_DATA: can be type month('January 2024') or type=day ('24jan2024')

  DATA_ = INPUT("&Prompt_DATA.", ANYDTDTE.);
  %LET HasComma = %SYSFUNC(INDEXC(&Prompt_DATA_LABEL., ','));
  %IF &HasComma. > 0 %THEN %DO;

I'm looking for a ',' so i know it means day. How can i better test the type of Prompt_Data?


Solution

  • This is a fine approach, just no reason to mix the macro language with the data step language.

    DATA_ = INPUT("&Prompt_DATA.", ANYDTDTE.);
    IF (INDEXC("&Prompt_DATA_LABEL.", ',')) THEN DO;
     
    
    END;
    

    Beyond that, SAS doesn't have types really here - just numeric and character. If it accepted a "month" type, it likely would be assigned the 1st of the month (so "January 2024" -> 01JAN2024), but you can't just test for that - the first of the month is after all a legal value for the day version as well.