Sas Extract Substring from String with Prxchange or Prxpson(Prxmatch(Prxparse()))

2 SOLUTIONS POSTED AT BOTTOM

My code

    data test;  
        extract_string = "<some string here>";
        my_result1 = prxchange(cat("s/^.*", extract_string, ".*$/$1/"), -1, "A1M_PRE");  
        my_result2 = prxchange(cat("s/^.*", extract_string, ".*$/$1/"), -1, "AC2_0M");  
        my_result3 = prxchange(cat("s/^.*", extract_string, ".*$/$1/"), -1, "GA3_30M");
        my_result4 = prxchange(cat("s/^.*", extract_string, ".*$/$1/"), -1, "DE3_1H30M");  
    run;

Desired results

Extract the number after _ but preceding M in strings that have M at the end. The result set should be:

    my_result1 = ""  
    my_result2 = "0"  
    my_result3 = "30"  
    my_result4 = "30"
David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.