BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
umesh1
Fluorite | Level 6
Hi All, I have below dummy data set. I would like to achieve below result in the last column. Result column in T or R depending on the consecutive zero of the row DATA TEST; INPUT ID T1 T2 T3 T4 T5 T6 T7; CARDS; 1 1 1 1 0 1 1 1 2 1 1 0 0 1 1 1 3 1 1 0 0 0 1 1 4 1 1 0 1 1 1 1 5 0 1 1 1 1 1 1 6 0 0 1 1 1 1 1 ; RUN; Result will look like as below 1 1 1 1 0 1 1 1 T 2 1 1 0 0 1 1 1 R 3 1 1 0 0 0 1 1 R 4 1 1 0 1 1 1 1 T 5 0 1 1 1 1 1 1 T 6 0 0 1 1 1 1 1 R
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Are the values only 0 and 1?  Are any missing?

If so you could try converting them to a string and checking the string for the pattern.

if index(cats(of t1-t7),'000') then result='T';
else result='R';

View solution in original post

2 REPLIES 2
Cynthia_sas
Diamond | Level 26

Hi:

  This seems like a scenario where you could use ARRAY processing if you need to worry about consecutive values. What about data like this:

1 1 1 1 0 1 1 1 T 
2 1 1 0 0 1 1 1 R 
3 1 1 0 0 0 1 1 R 
4 1 1 0 1 1 1 1 T 
5 0 1 1 1 1 1 1 T 
6 0 0 1 1 1 1 1 R 
7 1 1 1 1 1 1 1 T
8 1 0 1 0 1 0 1 ??

I assume that 7 would be a T, but what about 8 -- it has three 0 values, but not consecutive.

 

Cynthia

Tom
Super User Tom
Super User

Are the values only 0 and 1?  Are any missing?

If so you could try converting them to a string and checking the string for the pattern.

if index(cats(of t1-t7),'000') then result='T';
else result='R';

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
  • 2 replies
  • 900 views
  • 0 likes
  • 3 in conversation