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

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