Hello. Please see the code below. I am using the SAS University Edition (SAS Studio). I am not getting the correct output along with error messages. The output should reflect under columns (Ques1-Ques5) "Agree", "Strongly Agree", etc. I may be mixing apples and oranges here. Can anybody tell me how to correct my code or show me a correct version of my code? FYI: I am a student and following along in my book (p.59-60) in the book entitled: "Learning SAS by Example. A Programmer's Guide. 2nd Edition"
Code:
libname Learn1 '/folders/myshortcuts/New_folder';
data Learn1.Test_Scores1;
input ID Gender$ Age Salary Ques1-Ques5$;
datalines;
001 M 23 28000 1 2 1 2 3
002 F 55 76123 4 5 2 1 1
003 M 38 36500 2 2 2 2 1
004 F 67 128000 5 3 2 2 4
005 M 22 23060 3 3 3 4 2
006 M 63 90000 2 3 5 4 3
007 F 45 76100 5 3 4 3 3
;
run;
proc format;
value $Gender 'M' = 'Male'
'F' = 'Female'
' ' = 'Not Entered'
other = 'Miscoded';
value Age low-29 = 'Less than 30'
30-50 = '30 to 50'
51-high = '51+';
value $Likert '1' = 'Str Disagree'
'2' = 'Disagree'
'3' = 'No opinion'
'4' = 'Agree'
'5' = 'Str Agree';
run;
title "Data";
proc print data=Learn1.Test_Scores1;
id ID;
var Gender Age Salary Ques1-Ques5;
format Gender $Gender.
Age Age.
Ques1-Ques5 $Likert.
Salary Dollar11.2;
run;
Errors:
Try this you had if you really want Ques1-5 as strings
data Test_Scores1;
input ID Gender$ Age Salary Ques1 $ Ques2 $ Ques3 $ Ques4 $ Ques5 $;
datalines;
001 M 23 28000 1 2 1 2 3
002 F 55 76123 4 5 2 1 1
003 M 38 36500 2 2 2 2 1
004 F 67 128000 5 3 2 2 4
005 M 22 23060 3 3 3 4 2
006 M 63 90000 2 3 5 4 3
007 F 45 76100 5 3 4 3 3
;
run;
proc format;
value $Gender 'M' = 'Male'
'F' = 'Female'
' ' = 'Not Entered'
other = 'Miscoded';
value Age low-29 = 'Less than 30'
30-50 = '30 to 50'
51-high = '51+';
value $Likert '1' = 'Str Disagree'
'2' = 'Disagree'
'3' = 'No opinion'
'4' = 'Agree'
'5' = 'Str Agree';
run;
title "Data";
proc print data=Test_Scores1;
id ID;
var Gender Age Salary Ques1-Ques5;
format Gender $Gender.
Age Age.
Ques1-Ques5 $Likert.
Salary Dollar11.2;
run;
for numbers do this
data Test_Scores1;
input ID Gender$ Age Salary Ques1-Ques5;
datalines;
001 M 23 28000 1 2 1 2 3
002 F 55 76123 4 5 2 1 1
003 M 38 36500 2 2 2 2 1
004 F 67 128000 5 3 2 2 4
005 M 22 23060 3 3 3 4 2
006 M 63 90000 2 3 5 4 3
007 F 45 76100 5 3 4 3 3
;
run;
proc format;
value $Gender 'M' = 'Male'
'F' = 'Female'
' ' = 'Not Entered'
other = 'Miscoded';
value Age low-29 = 'Less than 30'
30-50 = '30 to 50'
51-high = '51+';
value $Likert 1 = 'Str Disagree'
2 = 'Disagree'
3 = 'No opinion'
4 = 'Agree'
5 = 'Str Agree';
run;
title "Data";
proc print data=Test_Scores1;
id ID;
var Gender Age Salary Ques1-Ques5;
format Gender $Gender.
Age Age.
Ques1-Ques5 Likert.
Salary Dollar11.2;
run;
Try this you had if you really want Ques1-5 as strings
data Test_Scores1;
input ID Gender$ Age Salary Ques1 $ Ques2 $ Ques3 $ Ques4 $ Ques5 $;
datalines;
001 M 23 28000 1 2 1 2 3
002 F 55 76123 4 5 2 1 1
003 M 38 36500 2 2 2 2 1
004 F 67 128000 5 3 2 2 4
005 M 22 23060 3 3 3 4 2
006 M 63 90000 2 3 5 4 3
007 F 45 76100 5 3 4 3 3
;
run;
proc format;
value $Gender 'M' = 'Male'
'F' = 'Female'
' ' = 'Not Entered'
other = 'Miscoded';
value Age low-29 = 'Less than 30'
30-50 = '30 to 50'
51-high = '51+';
value $Likert '1' = 'Str Disagree'
'2' = 'Disagree'
'3' = 'No opinion'
'4' = 'Agree'
'5' = 'Str Agree';
run;
title "Data";
proc print data=Test_Scores1;
id ID;
var Gender Age Salary Ques1-Ques5;
format Gender $Gender.
Age Age.
Ques1-Ques5 $Likert.
Salary Dollar11.2;
run;
for numbers do this
data Test_Scores1;
input ID Gender$ Age Salary Ques1-Ques5;
datalines;
001 M 23 28000 1 2 1 2 3
002 F 55 76123 4 5 2 1 1
003 M 38 36500 2 2 2 2 1
004 F 67 128000 5 3 2 2 4
005 M 22 23060 3 3 3 4 2
006 M 63 90000 2 3 5 4 3
007 F 45 76100 5 3 4 3 3
;
run;
proc format;
value $Gender 'M' = 'Male'
'F' = 'Female'
' ' = 'Not Entered'
other = 'Miscoded';
value Age low-29 = 'Less than 30'
30-50 = '30 to 50'
51-high = '51+';
value $Likert 1 = 'Str Disagree'
2 = 'Disagree'
3 = 'No opinion'
4 = 'Agree'
5 = 'Str Agree';
run;
title "Data";
proc print data=Test_Scores1;
id ID;
var Gender Age Salary Ques1-Ques5;
format Gender $Gender.
Age Age.
Ques1-Ques5 Likert.
Salary Dollar11.2;
run;
Thank you for the help.
It worked beautifully. I understand what I needed to do.
Again, thank you.
Pete
Thank you this was a great help..
could also just upload the data using the specified path
data Learn.Survey;
infile '/folders/myfolders/BookFiles/survey.txt';
input ID $ Gender $ Age Salary Ques1 $ Ques2 $ Ques3 $ Ques4 $ Ques5 $;
run;
/* Needed to label each Question out with the dollar sign afterwards instead of doing Ques1-Ques5, dumb */
proc format;
value $Gender 'M' = 'Male'
'F' = 'Female'
' ' = 'not listed'
other = 'miscoded';
value Age low-29 = 'below 30'
30-50 = '30 to 50'
51-high = 'above 51';
value $Likert '1' = 'Str Disagree'
'2' = 'Disagree'
'3' = 'No Opinion'
'4' = 'Agree'
'5' = 'Str Agree';
run;
title "Data Set Survey with Formatted Values";
proc print data = Learn.survey;
id ID;
var Gender Age Salary Ques1-Ques5;
format Gender $Gender.
Age Age.
Ques1-Ques5 $Likert.
Salary Dollar11.2;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.