BookmarkSubscribeRSS Feed
usuario_estudo
Calcite | Level 5

Hi,

 

I need a function in SAS that reads horizontally.

 

I have to create a variable "Number of completed months" that returns the value of months that are filled until it arrives empty (missing ".").

 

Example: 

 

 

IDMONTH_1MONTH_2MONTH_3MONTH_4MONTH_5MONTH_6MONTH_7MONTH_8"Number of completed months" 
110223165....4
2152111......2
3197198.....3
43386759321284..6
5100176902208188887788

 

Thnak you!

1 REPLY 1
Astounding
PROC Star

SAS can do this easily if the data behaves:

 

n_complete = n(of month_1 - month_8);

 

However, if you have the possibility of missing values in the middle:

 

month_1 = 10

month_2 = .

month_3 = 22

 

You would need to decide if the correct result is 2 vs. should it be 3.  The programming might have to change a little.

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 773 views
  • 0 likes
  • 2 in conversation