I am trying to learn SAS and run a basic command as shown in the textbook im readying but it seems to not be working. Below is the code i am running:
libname Jack "C where the file is located";
data survey02;
infile "C: where the file is located.... survey.txt";
input Id Gender $ Age Salary ques1-ques5;
run;
proc print;
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 set SURVEY with formatted values";
proc print data=survey02;
id ID;
var gender age salary ques1-Ques5;
format gender $gender.
age Age.
Ques1-Ques5 $likert.
salary Dollar11.2;
run;
When i run this i keep getting the error: You are trying to use the character format $LIKERT with the numeric variable ques1 in dataset WORK.SURVEY02. Im confused because im trying to make numeric values into character values so why wouldn't i include $, when i take it out it says: ERROR: The quoted string '1' is not acceptable to a numeric format or informat.
Ques1 is a NUMERIC variable in your data set. So, you must assign it a format that is appropriate for a numeric variable, the format name cannot begin with a $, and the values in the format must be written without quotes on the left of the equal sign, like this:
value Likert 1 = 'Str Disagree' ...
Ques1 is a NUMERIC variable in your data set. So, you must assign it a format that is appropriate for a numeric variable, the format name cannot begin with a $, and the values in the format must be written without quotes on the left of the equal sign, like this:
value Likert 1 = 'Str Disagree' ...
You have a numeric variable. You need a numeric format.
proc format;
value Likert
1 = 'Str Disagree'
2 = 'Disagree'
3 = 'No Opinion'
4 = 'Agree'
5 = 'Str Agree'
;
run;
Then you use it without the $.
format QUES1-QUES5 likert.;
@PilOSU wrote:
When i remove the $ from before it, i get the following error: The quoted string '1' is not acceptable to a numeric format or informat.
yes, I said above:
and the values in the format must be written without quotes on the left of the equal sign
but obviously you didn't do that part. You need to remove the quotes from around '1' so there are no quotes, and this will work for a numeric variable.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.