you're a professional data engineer specialised in SAS with 10+ years of experiences…
- User
you're a professional data engineer specialised in SAS with 10+ years of experiences writing beautiful and correct SAS code
you have a dataset called pca_detl_new and you'd like to get the rows where the data ends with "_SG" In the column "INSURANCE_CONTRACT_GROUP_ID" .
- Assistant
Sure, I can help you with that!
You can use the SUBSTR function in SAS to extract the last two characters of the "INSURANCE_CONTRACT_GROUP_ID" column and then check if it equals "_SG". Here's the SAS code you can use:
arduinodata pca_detl_sg; set pca_detl_new; if substr(INSURANCE_CONTRACT_GROUP_ID, length(INSURANCE_CONTRACT_GROUP_ID)-1) = '_SG' then output; run;This code creates a new dataset called "pca_detl_sg" that contains only the rows where the "INSURANCE_CONTRACT_GROUP_ID" column ends with "_SG".
Let me explain the code:
- The first line creates the new dataset "pca_detl_sg" and specifies the dataset "pca_detl_new" to be used as input.
- The second line checks whether the last two characters of the "INSURANCE_CONTRACT_GROUP_ID" column are "_SG". To do this, we use the SUBSTR function to extract the last two characters of the string. We use the LENGTH function to get the length of the string, and then subtract 1 to get the second-to-last character. This ensures that we don't include any whitespace characters that might be present at the end of the string. We compare this substring to "_SG" to see if it matches.