BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BaalaRaaji
Quartz | Level 8

Hi Team,

 

I have a variable called history which has 24 numbers in it.

example (111221122121112121111121) - qualifies as Ever2 /455444443211113212211221 qualifies in Ever 4

 

Can you advise the logic to use to create flags like in the 'history' variable if it has numbers > 2( that comes in the complete series anytime not looking at the position)then Ever2 .

 

 

I mean in that a particular variable i have 1 2months data...if the history variable has  > 2 then Ever2=1, if it has >4 then Ever 4= 1;

 

thanks for the help.

 

examples of the records for history.

 

111111111111111111111111
888887654323221211111111
000000000000000000000000
000000000000000000000000
000000000088888888888888
111111111121111211111111
000000000000011111111111
000000000000000000000000
000000000000000000000000
888888888888888888888888
000000000000110111111211
000000000000000000000000
432232143221212212111111
000000000000000000000000
000000000000001111121111
000000000000000000000000
000000000000000000000000
111111211111111111112112

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Not sure why 111221122121112121111121 qualifies as Ever2=1 given your rule is "numbers > 2"

 

See if below returns what you want. Else just amend the list of digits to search for.

data demo;
  input digits:$24.;
  Ever4 = (findc(digits,'56789')>0);
  Ever2 = (Ever4=0 and findc(digits,'34')>0);
  datalines;
111221122121112121113121
455444443211113212211221 
111111111111111111111111
888887654323221211111111
000000000000000000000000
000000000000000000000000
000000000088888888888888
111111111121111211111111
000000000000011111111111
000000000000000000000000
000000000000000000000000
888888888888888888888888
000000000000110111111211
000000000000000000000000
432232143221212212111111
000000000000000000000000
000000000000001111121111
000000000000000000000000
000000000000000000000000
111111211111111111112112
;
proc print data=demo;
run;

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

Not sure why 111221122121112121111121 qualifies as Ever2=1 given your rule is "numbers > 2"

 

See if below returns what you want. Else just amend the list of digits to search for.

data demo;
  input digits:$24.;
  Ever4 = (findc(digits,'56789')>0);
  Ever2 = (Ever4=0 and findc(digits,'34')>0);
  datalines;
111221122121112121113121
455444443211113212211221 
111111111111111111111111
888887654323221211111111
000000000000000000000000
000000000000000000000000
000000000088888888888888
111111111121111211111111
000000000000011111111111
000000000000000000000000
000000000000000000000000
888888888888888888888888
000000000000110111111211
000000000000000000000000
432232143221212212111111
000000000000000000000000
000000000000001111121111
000000000000000000000000
000000000000000000000000
111111211111111111112112
;
proc print data=demo;
run;

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

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