Detail question
I have a data set with A,B,C,D... attributes so in C I have {ACE,ALM,BDS} .
so when ever I got "ACE" in C then the output has to get 15 lines from the condition it has met and it has to go until the end of the row.
Can any one provide me the code
I'm not 100% this is what you are looking for but here is a solution for how I translated your question:
data have;
infile cards dsd ;
input a$ b$ c$ d$;
cards;
,one,,
,two,,
ACE,,,
,two,,
,three,,
,four,,
,five,,
,six,,
,seven,,
,eight,,
,nine,,
,ten,,
,eleven,,
,twelve,,
,thirteen,,
,fourteen,,
,fifteen,,
,sixteen,,
ACE,,,
,two,,
,three,,
;
run;
data want(drop=count ace_count);
set have;
count + 1;
if a = 'ACE' then count = 1;
retain ace_count;
if a = 'ACE' then ace_count = 1;
if count > 15 then ace_count = .;
if 1 <= count <= 15 and ace_count = 1 then output;
run;
I'm not 100% this is what you are looking for but here is a solution for how I translated your question:
data have;
infile cards dsd ;
input a$ b$ c$ d$;
cards;
,one,,
,two,,
ACE,,,
,two,,
,three,,
,four,,
,five,,
,six,,
,seven,,
,eight,,
,nine,,
,ten,,
,eleven,,
,twelve,,
,thirteen,,
,fourteen,,
,fifteen,,
,sixteen,,
ACE,,,
,two,,
,three,,
;
run;
data want(drop=count ace_count);
set have;
count + 1;
if a = 'ACE' then count = 1;
retain ace_count;
if a = 'ACE' then ace_count = 1;
if count > 15 then ace_count = .;
if 1 <= count <= 15 and ace_count = 1 then output;
run;
First of all thank you so much for the reply;
You are a genius
Can you also suggest me where to get information about RETAIN and all it uses.
Thank you again.
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 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: