title: Subsetting a dataset by selecting variables based on keywords in their name in SAS
body: <p>I hope someone can help. I have a large dataset imported to SAS with thousands of variables. I want to create a new dataset by extracting variables that have a specific keyword in their name. For example, the following variables are in my dataset:</p>
  
  <blockquote>
    <p>AAYAN_KK_Equity_Ask<br>
    AAYAN_KK_Equity_Bid<br>
    AAYAN_KK_Equity_Close<br>
    AAYAN_KK_Equity_Date<br>
    AAYAN_KK_Equity_Volume<br>
    AAYANRE_KK_Equity_Ask<br>
    AAYANRE_KK_Equity_Bid<br>
    AAYANRE_KK_Equity_Close<br>
    AAYANRE_KK_Equity_Date   </p>
  </blockquote>
  
  <p>I want to extract variables that end with _Ask and _Bid without knowing the rest of the variable's name. Is there a way to do that? I want to try using a do loop but don't know how to instruct SAS to compare each variable's last part of the name with _Ask or _Bid.</p>
  
  <p>Afterwords. I want to create a new variable for each set that starts with full name of the variable except the last part (Which is _Ask or _Bid). Can I do that in using an assignment statement?</p>