BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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 codeUntitled.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Steelers_In_DC
Barite | Level 11

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;

View solution in original post

3 REPLIES 3
Steelers_In_DC
Barite | Level 11

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;

siddharthpeesary
Calcite | Level 5

First of all thank you so much for the reply;

You are a genius Smiley Happy

Can you also suggest me where to get information about RETAIN and all it uses.

Thank you again.

Steelers_In_DC
Barite | Level 11
You are welcome 🙂 I would google SAS Retain and look around. There is a ton of information. I prefer anything that is from a sas users group. There's a lot of information available from classes too: https://onlinecourses.science.psu.edu/stat481/node/36
http://www.mwsug.org/proceedings/2009/stats/MWSUG-2009-D14.pdf

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1192 views
  • 0 likes
  • 2 in conversation