I am using SAS University Edition on a Mac, I need help in how to to code per the questions after the dataset:
SAS Dataset
data psych;
input ID $3. Ques1-Ques10 Score1-Score5;
datalines;
001 1 3 2 4 5 4 3 4 5 4 90 88 92 95 90
002 3 3 . . 3 4 5 5 1 . 64 64 77 72 71
003 . . . . 5 5 4 4 3 3 68 69 80 75 70
004 5 3 4 5 . 5 4 3 3 . 88 77 66 77 67
005 5 4 3 2 1 1 2 3 4 5 92 93 94 95 99
006 4 5 1 3 2 5 3 1 1 1 55 65 71 85 91
007 3 2 2 1 5 4 5 3 2 2 60 70 88 79 82
008 2 1 1 5 5 4 4 2 1 3 65 87 90 60 55
009 1 1 1 3 2 2 3 5 4 4 71 81 91 77 88
010 2 3 3 4 1 5 2 2 3 1 64 69 61 70 70
;
runs;
In one data step --
ID Ques1 . . . Ques10 RQues1 . . . RQues10 ToTQues Missing Score1 . . . Score5
Transpose tutorials
Wide to Long:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/
https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/
Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/
Those should get you started. If you then post what you've tried, we'll be happy to help but for something that's clearly homework its a good idea to show what you've attempted first so we don't feel like we're doing it for you. Happy to help with any issues you encounter though.
@RRzio11 wrote:
I am using SAS University Edition on a Mac, I need help in how to to code per the questions after the dataset:
SAS Dataset
data psych;
input ID $3. Ques1-Ques10 Score1-Score5;
datalines;
001 1 3 2 4 5 4 3 4 5 4 90 88 92 95 90
002 3 3 . . 3 4 5 5 1 . 64 64 77 72 71
003 . . . . 5 5 4 4 3 3 68 69 80 75 70
004 5 3 4 5 . 5 4 3 3 . 88 77 66 77 67
005 5 4 3 2 1 1 2 3 4 5 92 93 94 95 99
006 4 5 1 3 2 5 3 1 1 1 55 65 71 85 91
007 3 2 2 1 5 4 5 3 2 2 60 70 88 79 82
008 2 1 1 5 5 4 4 2 1 3 65 87 90 60 55
009 1 1 1 3 2 2 3 5 4 4 71 81 91 77 88
010 2 3 3 4 1 5 2 2 3 1 64 69 61 70 70
;
runs;
In one data step --
- Create 10 new variables RQues1 ~ RQues10 by using ARRAY statement to reverse the values (e.g., 1 to 5, 2 to 4, etc.) of Ques1 to Ques10. Notice that original missing data are still missing in new variables.
- Create a new variable ToTQues by using SUM function to make a summation number from variables Ques1 to Ques10.
- Create a new variable Missing to count how many variables from Ques1 to Ques10 with missing data in each ID. (Hint: there is SAS function to count variables with missing data).
- Create 5 new variables Pass1 ~ Pass5 by using ARRAY statement to determine whether variables Score1 ~Score5 are greater than or equal to 65, 70, 60, 62, 68, respectively. If yes, the new variable is equal to 1; otherwise, it is equal to 0. Notice that (65, 70, 60, 62, 68) should be defined in a temporary array.
- Rearrange the position of variables in the final data set by the following order:
ID Ques1 . . . Ques10 RQues1 . . . RQues10 ToTQues Missing Score1 . . . Score5
- Print all variables in the output window and copy to below.
Thank you!
This is what I have so far:
Why do you create the libref if you are not going to use it?
To reference a dataset using the libref you need to use a "two level" name. A name with a period in the middle. If you use just a "one level" name then SAS will assume you want to use WORK as the libref. So this statement
data psych;
is the same as
data work.psych;
To store this original data into "permanent" dataset in the PSYCH libref (or "library") you would use something like:
data psych.original;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.