data ds;
set sashelp.class;
if mod(_n_,2)=1 then seq=1;output;
else mod(_n_,2)=0 then seq=1+1;
output;
keep name seq;
proc print noobs;
run;
required output
Name Seq
Alfred 1
Alice 1
Alice 1
Barbara 2
Carol 2
Carol 2
Henry 3
James 3
James 3
Jane 4
Janet 4
Janet 4
Jeffrey 5
John 5
John 5
Joyce 6
Judy 6
Judy 6
Louise 7
Mary 7
Mary 7
Philip 8
Robert 8
Robert 8
Ronald 9
Thomas 9
Thomas 9
William 10
Making reasonable assumptions about what the input looks like, here's what I came up wth:
data want;
set have;
if mod(_n_, 2) then do;
seq + 1;
output;
end;
else do;
output;
output;
end;
run;
So you are usig a lot of the right tools, but definitely need to tweak the program to get the desired result.
Making reasonable assumptions about what the input looks like, here's what I came up wth:
data want;
set have;
if mod(_n_, 2) then do;
seq + 1;
output;
end;
else do;
output;
output;
end;
run;
So you are usig a lot of the right tools, but definitely need to tweak the program to get the desired result.
Could you explain the desired output? It appears that you want Alfred once, Alice twice, Barbara once, Carol twice, and so on. What is the logic?
I see you already have a solution. Here's is an alternative that eschews DO groups:
data want;
set have;
seq+mod(_n_,2);
output;
if mod(_n_,2)=0 then output;
run;
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!
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.