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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 1 reply
  • 479 views
  • 1 like
  • 2 in conversation