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

Hello,

 

I'm comparing two let variables that have multiple strings in each and I want to be able to tell if a string has been added to the second let variable. For an example if I have the following:

 

%let all_codes_jan = a, b, c, d, e, f;
%let all_codes_march = a, b, c, d, e, f, g;

 

I want to find that the code g was added and is a value in the second let variable that is not included in the first let variable. I have used in and not in before in proc sql but I dont know how to do this when there are many codes in each variable, and they are not columns in a table. 

 

Thanks in advance for any help you can offer!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
You're right. SQL handles this type of problem easily, as long as you keep your data in data sets. Why create macro variables when all they do is make the programming more complex? Do you have a choice?

View solution in original post

4 REPLIES 4
Astounding
PROC Star
You're right. SQL handles this type of problem easily, as long as you keep your data in data sets. Why create macro variables when all they do is make the programming more complex? Do you have a choice?
TheRealHunterC
Calcite | Level 5
Yes it sounds like I should just keep it simple.
ballardw
Super User

What does the result of your comparison actually look like? An assigned value to a macro variable, if so what does it look like? A value in a data set? A message written to the log or results window?

 

And is this "added" an "added at the end" (as your example implies) or "some value inserted into a random location"?

Or what if the order of values changes? is "a,b,c" the same as "b,c,a"? If not, what is the result?

 

 

Is there any particular reasons you are placing commas in the values? If you want to do this with macro coding then the presence of the commas will likely make the code much more complicated because the comma is the delimiter in functions.

ChrisNZ
Tourmaline | Level 20

For your example (one-character strings), the verify macro would be useful.

See here https://www.lexjansen.com/phuse/2010/po/PO05.pdf

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 1379 views
  • 3 likes
  • 4 in conversation