BookmarkSubscribeRSS Feed
ballardw
Super User

@Ronein wrote:

Hello

I have the following challenge.

Let's say that there is an input data set .

I want to check which numbers in last column are new in comparison to previous column(one column before last column).

I want to check which numbers in one column before last column are not existing in last column.

 

I think that in the program we need to check how many columns are in in input data set and then we can compare last column with one column before last.

For example:

In the following example if we compare last column with one column before last:

9,10,11  are new members

8,9 left

 

I want to create a new outcome data set  with two columns: new and left

 

data tbl;
input x1801 x1802 x1803 x1804 x1805 x1806;
cards;
1 1 6 1 1 2
2 2 1 2 2 3
3 3 2 3 3 4
4 4 3 4 5 5
5 5 4 8 8 8
    5 9 9 10
;
run;

 


Does this requirement have anything to do with a data source that you keep "adding columns" to a base data set?

If so fix the data model. You are making lots of assumptions of what "last column" might mean and there is difficult to be sure that the columns you compare are what you think they are if the columns keep changing.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 15 replies
  • 2698 views
  • 2 likes
  • 6 in conversation