SAS: Create a new variable from a character variable's value
Posted on 2015-02-23
I am using SAS (statistical analysis software).
I have a SAS dataset with 50 variables called ID1-ID50 and 50 variables called Score1-Score50. This dataset has test item scores from a 50 item test. There is one record per examinee. However, the dataset contains data from dozens of different test forms. The items are from an item bank. Each item is identified in the item bank with a 6-digit master ID number. For the first examinee, ID1 might be item 143576; for another examinee, ID1 might be 437892, etc.
I want to create a dataset that scores the item scores (from the Score1-Score50 variables) in which the variable names are the master Item ID numbers. For example, the ID numbers might be Item_143576, item_437892, etc. There are 2,000 different ID numbers, so there will be about 2,000 item score variables in the new dataset.
The simplest way would be something like CALL SYMPUT for data step variables rather than macro variables.
I could use PROC FORMAT to create a huge lookup table of the ID numbers and their index in a 2.000 element array. Then I could use a PUT statement to grab the appropriate array index value for the stored ID value. I was hoping there is something more elegant so that I don't have to create thousands of lines of code to store my proc format and my array statement (with 2,000 variable names).