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

Hello-,

 

I have this data where the observations are in character with colon in the names:

hc_education

Associate's degree

 

 

Bachelor's degree
Graduate degree
High school diploma/GED
I attended 12th grade but did not receive a diploma
I completed 10th grade (11 years of school)
I completed 11th grade (12 years of school)
I completed 6th grade (7 years of school)
I completed 9th grade (10 years of school)
I completed high school and graduated or received a GED (13 years of school)
I completed less than 6th grade (less than 7 years of school)
I completed some college or received an associate's degree
I received a bachelor's degree (4 years of college)
I received a graduate degree or studied beyond a bachelor's degree
Less than high school
Some college
Frequency Missing = 9

 

Some of the observations such as :  Associate's degree , Bachelor's degree etc have colon (') before s. Once I apply this code to change this to number:

 

data first1;
set BMII;
if hc_education in ('I attended 12th grade but did not receive a diploma','I completed 10th grade (11 years of school)',
'I completed 11th grade (12 years of school)','I completed 6th grade (7 years of school)','I completed 9th grade (10 years of school)',
'I completed less than 6th grade (less than 7 years of school)','Less than high school') then edu=1; else if hc_education in
('I completed high school and graduated or received a GED (13 years of school)','High school diploma/GED', 'Some college')then edu=2;
else if hc_education in ('I received a graduate degree or studied beyond a bachelor's degree','Associate's degree','Bachelor's degree','Graduate degree'')
then edu=3;

run;

 

 I got error:

104 else if hc_education in ('I received a graduate degree or studied beyond a bachelor's
-----------------------------------------------------------
---
----------
---
49 49
49
49
-
22
-
76
104! degree','Associate's degree','Bachelor's degree','Graduate degree'')
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS
release. Inserting white space between a quoted string and the succeeding identifier
is recommended.

ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,
a datetime constant, a missing value, iterator, (, ), ','.

ERROR 76-322: Syntax error, statement will be ignored.

105 then edu=3;

 

Please How do I fix this in the code. I cannot change in the Data set.


 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Have you tried wrapping with double quotes?

 

 if hc_education in ("I received a graduate degree or studied beyond a bachelor's degree","Associate's degree","Bachelor's degree","Graduate degree'')

 

If the value has embedded single quote, wrap it with double quotes and vice versa

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Have you tried wrapping with double quotes?

 

 if hc_education in ("I received a graduate degree or studied beyond a bachelor's degree","Associate's degree","Bachelor's degree","Graduate degree'')

 

If the value has embedded single quote, wrap it with double quotes and vice versa

Reeza
Super User
You should try using a format instead. It makes things like this much easier to work with.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 678 views
  • 2 likes
  • 3 in conversation