BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yautja33
Calcite | Level 5

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:

ERROR: You are trying to use the character format $LIKERT with the numeric variable Ques1 in data set LEARN1.TEST_SCORES1.
ERROR: You are trying to use the character format $LIKERT with the numeric variable Ques2 in data set LEARN1.TEST_SCORES1.
ERROR: You are trying to use the character format $LIKERT with the numeric variable Ques3 in data set LEARN1.TEST_SCORES1.
ERROR: You are trying to use the character format $LIKERT with the numeric variable Ques4 in data set LEARN1.TEST_SCORES1.
110 run;
1 ACCEPTED SOLUTION

Accepted Solutions
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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;

 

 

View solution in original post

5 REPLIES 5
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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;

 

 

yautja33
Calcite | Level 5

Thank you for the help.

It worked beautifully.  I understand what I needed to do.

Again, thank you.

Pete

Meet_SAS
Fluorite | Level 6

Thank you this was a great help..

Reeza
Super User
Your LIKERT format is created as a character format, with the $, but the log is saying that Ques1-Ques5 is numeric, so you need a numeric format, not a character format.
skatethejake
Fluorite | Level 6

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;