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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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' ...

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

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' ...

--
Paige Miller
PilOSU
Obsidian | Level 7
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.
Reeza
Super User

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.;
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
PilOSU
Obsidian | Level 7
Welp... that was an easy fix.... the textbook has it listed wrong then. Thank you

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!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1489 views
  • 2 likes
  • 3 in conversation