Posts

Showing posts with the label substr
Extracting the First Three Alphabetic Characters in SAS: A Comparative Guide Extracting the First Three Alphabetic Characters in SAS: A Comparative Guide When working with "Agreement" numbers that contain both alphabetic and numeric characters, there are several approaches you can use in SAS to extract the first three alphabetic characters. Below, I’ll discuss three common methods: substr with findc , substr with compress , and substr with left . Each method has its own advantages and disadvantages, depending on the structure of your data and your specific needs. Approach 1: substr with findc char_part = substr(Agreement, 1, findc(Agreement, '0123456789')-1); Explanation: This approach finds the position of the first numeric character in the Agreement string using findc , and then extracts all characters before that position using substr . It works well if the alphabetic part of the "Agreement" is always at the beginnin...

SAS Interview Questions: Base SAS

Very Basic: What SAS statements would you code to read an external raw data file into a DATA step? You would use the INFILE statement to specify the location of the external raw data file, and the INPUT statement to read in the data into the variables in a SAS dataset. How do you read in the variables that you need? You use the INPUT statement with specific column pointers, such as @5 or 12-17 , to define where each variable is located in the raw data file. Are you familiar with special input delimiters? How are they used? Yes, special input delimiters like DLM and DSD are used to specify how fields are separated in the data. They are included in the INFILE statement. For example, the DLM option can be used to specify a comma as a delimiter for CSV files. The DSD option is used for comma-separated values (CSV) files and treats consecutive delimiters as missing values and ignores delimiters enclosed in quotation marks. If reading a variable-length file with fixed inp...