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.

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
  • 599 views
  • 1 like
  • 2 in conversation