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

Hi!

 

I have a dataset that has degree program names that end with the degree type. I want to create a new variable with just these variable types that are tacked on to the end of the program names (BS, BSEd, M.Ac, MS, etc.). I figured a wildcard% would work for this but it is not working like I thought it would. Here are two tests I did trying to get it to work:

data Programs_With_States_IND;
	set work.PROGRAMS_WITH_STATES_IND;
		if Degree_Program_Name like '%BS%'
		then Degree_Type = 'BS';

		else if Degree_Program_Name like '%M.Ac%'
		then Degree_Type = 'M.Ac';

		else if Degree_Program_Name like '%MAT%'
		then Degree_Type = 'MAT';

		else if Degree_Program_Name like '%MA%'
		then Degree_Type = 'MA';
run;
proc sql;
	create table prog_test as
		select *, case 
			when Degree_Program_Name like '%BS%' then 'BS'
			
			when Degree_Program_Name like '%MA%' then 'MA'
		end as Degree_Type
		from work.programs_with_states_ind;
quit;

Any help would be appreciated! Thanks!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
LIKE isn't valid in a data step, instead look at the FIND() and INDEX() functions for similar functionality.

View solution in original post

1 REPLY 1
Reeza
Super User
LIKE isn't valid in a data step, instead look at the FIND() and INDEX() functions for similar functionality.

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
  • 1 reply
  • 530 views
  • 1 like
  • 2 in conversation