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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 808 views
  • 0 likes
  • 2 in conversation