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

Hi experts, 

I am a SAS neophyte. I am trying to assign different values to a variable  based on other variable values in SAS DATA step. Please do not suggest case when expressions of proc sql(which I already know).

Please point out where my code went wrong and also suggest what I need to do. Appreciate your patience and support in advance. My code  looks like this;

Data student;

set list (keep= studentid student_name student_type specialty1 stream specialty2 specialtyType1) ;
length specialtyType1 $15.;
specilatyType1 =' ';
if (student_type IN ('rational', 'hardworking') or (student_type= 'Active' and specialty1 IN ('math', 'science', 'computer science')))
then specilatyType1=' Stem';
else specilatyType1= 'Non stem';

end';
run;

1 ACCEPTED SOLUTION

Accepted Solutions
6 REPLIES 6
sbxkoenk
SAS Super FREQ

What's the

end';

doing there?

Koen

inquistive
Quartz | Level 8
My apologies. The apostrophe evaded my eyes. it's not in my code.
PaigeMiller
Diamond | Level 26

You have the following line of code

 

end';

which should be deleted.

 

Other than that, why do you think anything is wrong? Explain.

--
Paige Miller
inquistive
Quartz | Level 8
My apologies. the apostrophe evaded my eyes. it's not in my code.
WarrenKuhfeld
Ammonite | Level 13

You will also want to spell "specialty" consistently.

ballardw
Super User

@inquistive wrote:

Hi experts, 

I am a SAS neophyte. I am trying to assign different values to a variable  based on other variable values in SAS DATA step. Please do not suggest case when expressions of proc sql(which I already know).

Please point out where my code went wrong and also suggest what I need to do. Appreciate your patience and support in advance. My code  looks like this;

Data student;

set list (keep= studentid student_name student_type specialty1 stream specialty2 specialtyType1) ;
length specialtyType1 $15.;
specilatyType1 =' ';
if (student_type IN ('rational', 'hardworking') or (student_type= 'Active' and specialty1 IN ('math', 'science', 'computer science')))
then specilatyType1=' Stem';
else specilatyType1= 'Non stem';

end';
run;


When a question like " point out where my code went wrong" arises the first thing to ask, is what did the LOG look like. Copy the entire log including all notes, messages, warnings or erorrs, for the data step or procedure that you think something went wrong with, on the forum open a text box using the </> icon above the message window and paste the log text into the box.

 

Then things like retyped errant apostrophes are not the problem.

Another possible typing error but if actually in your data different spellings of your variable.

length specialtyType1 $15.;
specilatyType1 =' ';

Which defines a length for one variable but the SPECILATY variable will have a length of 1. Then in the later statements you attempt to assign values to the one character length variable:

then specilatyType1=' Stem';
else specilatyType1= 'Non stem';

Spelling counts in programming.

You should have a note in the Log that variable Speciality is uninitialized. Which if you copy the log as requested we would have seen an pointed out sooner.
.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 6 replies
  • 2370 views
  • 4 likes
  • 5 in conversation