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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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