BookmarkSubscribeRSS Feed
mcmaxwell
Fluorite | Level 6

For my research I gave students a motivation survey at several points throughout the semester to see how motivation changes over time. The survey measures five motivational constructs. My dataset looks like this: 

Capture2.PNG

SUID is the identifier, T is the time I gave the survey (SM1, SM2, SM3, and SM4), and SE_A - CLB_A are the motivational constructs measured by the survey. 

I would like to make a line graph showing change in motivational constructs over time. To do this, I want to reorganize my data to have the following columns: 

SUID   T   Construct   Value

So, for example, each student would have 5 rows for each timepoint (there are four timepoints and five constructs). 

I used the following code to try and transpose my data: 

/** transpose some of the data **/ 
proc transpose data=all out=transposed name=construct; 
	by notsorted SUID notsorted T; 
	var SE_A TV_A IGO_A EGO_A CLB_A; 
	id SUID; 
run;

and my resulting data looks like this: 

Capture3.PNG

Is there a way that I can combine all of the columns labeled with SUID numbers into one column called "Value" without having to type out each SUID number in my code? Or is there a better way to transpose my data to get my desired outcome? 

 

Thank you in advance! 

3 REPLIES 3
Reeza
Super User
What happens if you remove the ID statement entirely?
PGStats
Opal | Level 21
proc transpose data=all out=transposed(rename=col1=value) name=construct; 
	by SUID  T notsorted; 
	var SE_A TV_A IGO_A EGO_A CLB_A; 
run;
PG
ballardw
Super User

You are making harder to create any sort of comparison across time graph with this approach.

You would be better off if your "time" variable were some sort of number in all likelihood, even just a integer representing order.

 

By making a separate variable for each subject/time it just gets harder to make any sort of meaningful graph.

 

data example;
  input id time measure1 measure2;
datalines;
1 1 25 22
2 1 33 34
3 1 47 49
1 2 22 20
2 2 36 31
3 2 46 49
1 3 28 21
2 3 38 32
3 3 37 39
1 4 21 29
2 4 34 31
3 4 46 41
1 5 29 23
2 5 40 45
3 5 49 43
;

proc sgplot data=example;
 title "All id same measure";
 series x=time y=measure1/group=id;
run;

proc sort data=example;
   by id;
run;

proc sgplot data=example;
 title "By id all measures";
 by id;
 series x=time y=measure1/;
 series x=time y=measure2/;
 yaxis label='Score';

run; title;

Now, manipulate the above example data set the same way and make graphs.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 731 views
  • 0 likes
  • 4 in conversation