Skip to content
TheChatArchiveThe Chat Archive
Googlegemma-3-27b-it· GoogleHugging Face LMArena Human Preference 140K

sas code regular expresion select rows with column col1 start with raport_nowy case…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with DeepSeekdeepseek-v3-0324’s answer.
  1. User

    sas code regular expresion select rows with column col1 start with raport_nowy case insensitive

  2. Google Assistant
    data want;
      set have;
      if prxmatch('/raport_nowy/i', col1) then do;
        output;
      end;
    run;
    

    Explanation:

    • data want;: Creates a new dataset named want to store the selected rows.
    • set have;: Reads data from the existing dataset named have. Replace have with the actual name of your dataset.
    • if prxmatch('/raport_nowy/i', col1) then do;: This is the core of the code.
      • prxmatch(pattern, source): This SAS function checks if a regular expression pattern matches within a character string source.
      • '/raport_nowy/i': This is the regular expression pattern.
        • raport_nowy: This is the literal string you're looking for at the beginning of col1.
        • /: Delimiters for the regular expression pattern.
        • i: This is a modifier that makes the match case-insensitive. Without the i, the match would only work if col1 started with "raport_nowy" exactly (lowercase).
      • col1: This is the character variable you're searching within.
    • output;: If the prxmatch function returns a non-zero value (meaning a match was found), the output statement writes the current row to the want dataset.
    • end;: Closes the do block.
    • run;: Executes the data step.

    How it works:

    The code iterates through each row of the have dataset. For each row, it checks if the col1 variable starts with "raport_nowy" (case-insensitively) using the prxmatch function. If a match is found, the row is written to the want dataset.

    Example:

    Let's say your have dataset looks like this:

    data have;
      input col1 $;
      datalines;
    raport_nowy_2023
    Raport_Nowy_2024
    other_data
    raport_nowy_test
    RAport_NOWY_example
    ;
    run;
    

    After running the code, the want dataset will contain:

    col1
    raport_nowy_2023
    Raport_Nowy_2024
    raport_nowy_test
    RAport_NOWY_example
    

    Important Considerations:

    • Dataset Names: Replace have and want with the actual names of your input and output datasets.

    • Variable Type: Make sure col1 is a character variable (indicated by the $ in the input statement or the variable attributes). If it's a numeric variable, you'll need to convert it to character first using the put function:

      if prxmatch('/raport_nowy/i', put(col1, $)) then do;
        output;
      end;
      
    • Regular Expression Complexity: For more complex matching requirements, you can use more advanced regular expression syntax within the prxmatch function. Refer to the SAS documentation for details: https://support.sas.com/documentation/cdl/en/sasdoc/9.4/lrref/sasdoc/prxmatch.htm

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.