DATA Step, Macro, Functions and more

Data Logic

Reply
Occasional Contributor
Posts: 12

Data Logic


All,

I have the following dataset, if the value of the 1st observation in column text is "yyy" then output only first obs or else output all the
observation from the datasets


Case 1

have
text id1 id2 id3
yyy 123 145 345
zzz 899 134 878
ccc 881 jk kjk

 

want
text id1 id2 id3

 


Case 2

have
text id1 id2 id3
mmm 123 145 345
zzz 899 134 878
ccc 881 jk kjk


want
text id1 id2 id3
mmm 123 145 345
zzz 899 134 878
ccc 881 jk kjk


Thanks
Al

Super User
Super User
Posts: 8,279

Re: Data Logic

[ Edited ]

It doesn't look like you want to output ANY observations.

 

data want ;
  set have ;
  if _n_=1 and text='yyy' then stop;
run;
Occasional Contributor
Posts: 12

Re: Data Logic

sorry i do  .. my mistake ..

 

 

 

i want the following dataset with only 1st obs if text="yyy"

 

text id1 id2 id3
yyy 123 145 345

 

 

Super User
Posts: 6,934

Re: Data Logic

A simple variation on Tom's program handles both cases:

 

data want;

set have;

output;

if _n_=1 and text='yyy' then stop;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 183 views
  • 1 like
  • 3 in conversation