Hello everyone,
I have been struggling with this problem for a few days, and I haven't found something that quite works the way I want it to work. I'm sure someone with a bit more experiance will know exactlly how to do it! Thank you for the help! Here goes!
I have 2 data sets, one has test name and a test name ID.
The other is from a proc mean procedure and has student ID numbers, the average, and then every cell has the average score for that student in that test. The variable names have test_1, test_2, ect... and these correspond to the test name ID in the name data set. The variable names in the proc mean data set are not in ordet, so I can't simpily assign it. I need to sort these values somehow, but the variable names are character type.
I am trying to find a way to assign the names (from the name data set) to the variable names (in the proc mean data set).
The other thing is that I would want to keep as much of the name as possible, some names have (), or # and % signs, and I want to keep those so that we can understand how the test was measured.
In my sample data there are 12 test, and I could simpily rename all the variables, but the ture data set has 300 test and like 10000 students.
I welcome any suggestions!
Thank you again!
mean_table
record | statname | test_5 | test_11 | test_7 | test_9 | test_1 | test_4 | test_8 | test_2 | test_12 |
1234 | average | 3 | 9 | 7.4 | 0.09 | 100 | 4 | 7 | 5 | 1 |
1235 | average | 3.2 | 9.1 | 7.3 | 0.04 | 101 | 4.3 | 6 | ||
1236 | average | 3.4 | 9 | 7.1 | 0.02 | 103 | 4.5 | 5 | 6 | 1 |
1237 | average | 2.6 | 9.5 | 7.9 | 0.08 | 99 | 4.6 | 6 | 3 | 1 |
1238 | average | 2.1 | 9.6 | 7.3 | 0.01 | 98 | 4.7 | 7 | 6 | 1 |
1239 | average | 3.2 | 9.3 | 7 | 0.05 | 90 | 4.7 | 2 | 1 |
name_table
test_name | test_id |
yellow# 2 | 1 |
blue#2 | 2 |
red | 3 |
pink(30%) | 4 |
green | 5 |
jack.and.jill | 6 |
yellow++ | 7 |
black | 8 |
white | 9 |
john? | 10 |
cyan(blue) | 11 |
raspberry=200 | 12 |
Have you considered not renaming all the variables, but just applying labels that carry the vital information?
It really depends on what you need to do with these data, but labels might be as or more useful than variable names.
I agree with @collinelliot. Labels would be a lot easier. Try the following:
proc sql noprint; select catt('label test_',test_id,'="',test_name,'";') into :labels separated by ' ' from name_table ; quit; data want; set mean_table; &labels.; run;
and then simply show the labels rather than the variable names.
Art, CEO, AnalystFinder.com
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.