BookmarkSubscribeRSS Feed
Justin9
Obsidian | Level 7

I have got a dataset and I am trying to find values in a character variable that might have been a new addition between each month.

 

I know that a proc freq can list out the values and the frequency for a variable, but can someone please help to provide some code that would output the new values that are different when comparing two months together (as there are over 100 values in the variable, so it would be difficult to manually compare which values are new for the most recent month vs the previous month)?

The screenshot below is just an extract example (there are over 100 values in the variables that I am looking at), but what would be the best way to:

1. Create an output where it shows any new values that are new when comparing month-to-month. In the example below, the output would output "Orange" (and possibly show how many times it appears), as "Orange" appears for a person in May but not in April.

2. Output the differences in the values between the two months (i.e. highlight any colours that do not appear in both, as there are also some variables in my dataset where there will be one colour in one month but not the other, then a different colour in the other month vs the month before)

Justin9_0-1622561459413.png

 

 

 

 

3 REPLIES 3
ballardw
Super User
proc sql;
    select distinct variable from dataset where month=<month value>
    except 
    select distinct variable from dataset where month=<previous month value>
    ;
quit;

Might be one way. The "except" reports values, or combinations of variable values found in the first set but not the second.

 

tomrvincent
Rhodochrosite | Level 12
What have you tried to do so far?
Justin9
Obsidian | Level 7
Hi, I've only done a simple proc freq, but I'm looking for a more efficient way of comparing and identifying any new values that might have been used in the latest month (when comparing it to the previous month), as there are over one hundred values in each month and it is difficult to compare which are the same/different

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1915 views
  • 0 likes
  • 3 in conversation