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;

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