BookmarkSubscribeRSS Feed
Curly
Fluorite | Level 6

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

recordstatnametest_5test_11test_7test_9test_1test_4test_8test_2test_12
1234average397.40.091004751
1235average3.29.17.30.041014.36  
1236average3.497.10.021034.5561
1237average2.69.57.90.08994.6631
1238average2.19.67.30.01984.7761
1239average3.29.370.05904.7 21

 

name_table

test_nametest_id
yellow# 21
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
2 REPLIES 2
collinelliot
Barite | Level 11

 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.

art297
Opal | Level 21

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 618 views
  • 0 likes
  • 3 in conversation