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

Hello Team,

 

I need verify if the numbers of rows are increased in months. 

 

This is my table:

 

 

DATA want;
 INPUT TABLE_NAME $ MONTH NOBS GRUP;
CARDS;
TABLE_A 202101 1234 1
TABLE_A 202102 1235 1
TABLE_A 202103 1236 1
TABLE_A 202104 1237 1
TABLE_A 202105 1238 1
TABLE_A 202106 1239 1
TABLE_A 202107 1230 1
TABLE_B 202101 1000 2
TABLE_B 202102 500 2
TABLE_B 202103 700 2
TABLE_B 202104 300 2
;
RUN;

i need compare the nobs of the first month with next moth

 

 

Ex: Compare nobs in Grup 1 - > 202101 with 202102, 202102 with 202103, 202103 with 202104.....

 

and if the month is less than the next month, status = 'true' else 'false', the first month of the grup can start with "TRUE"

 

What i need:

Sk1_SAS_0-1626984483768.png

 

Thanks!!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Look at the DIF function for starters.

data want;
set have;
by table_name;
dif = dif(NOBS);
if first.table_name or dif>0 then status="TRUE";
else status="FALSE";
run;

View solution in original post

3 REPLIES 3
Reeza
Super User

Look at the DIF function for starters.

data want;
set have;
by table_name;
dif = dif(NOBS);
if first.table_name or dif>0 then status="TRUE";
else status="FALSE";
run;
Sk1_SAS
Obsidian | Level 7

Thank you!

 

How can i start with "TRUE" for the first month of the ids? i can not compare the first one.

 

 

Reeza
Super User
If first.table_name will take care of that. I made a mistake and typed out first.month in my first version of the code, updated it for you here.

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
  • 3 replies
  • 950 views
  • 1 like
  • 2 in conversation