BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

Hi, need your help please.

data want;
set have;
input id test $ result $;
1 GCCX NEG
1 GCCXO NEG
1 GCCX POS
2 GCCX NEG
3 GCCXO POS
3 GCCXO NEG
3 GCCX NEG
4 GCCX NEG
5 GCCX POS
5 GCCX POS
RUN;

I would like to have the our put like this:
 id test $ result $;
1 GCCX POS
2 GCCX NEG
3 GCCX POS
4 GCGX NEG
5 GCCX POS

if an id has at least one positive then i wold like to have it count once as pos.
if an id has no pos only neg then count that id only once as neg.  it does ot matter if it is GCCX OR GCCXO.



5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20
data have;
input id test $ result $;
datalines;
1 GCCX NEG
1 GCCXO NEG
1 GCCX POS
2 GCCX NEG
3 GCCXO POS
3 GCCXO NEG
3 GCCX NEG
4 GCCX NEG
5 GCCX POS
5 GCCX POS
;

data want;
   r='NEG';
   do until (last.id);
      set have;
      by id;
      if result='POS' then r='POS';
   end;
   result = r;
run;
Dhana18
Obsidian | Level 7

proc sort data=SURRGWED.Epidata_COMBINED_RESULT;
by ClientID;
RUN;
data want;
r='NEG';
do until (last.ID);
set have;
by ID;
if result='POS' then r='POS';
end;
result = r;
run;
proc freq data=want;
table RESULT*r/NOROW NOCOL NOPERCENT;
RUN;

 

it did not give me positive results. here is the put put.

                  result Neg

r    neg      4839

PeterClemmensen
Tourmaline | Level 20

Seems like your actual ID variable is ClientID and not just ID

ghosh
Barite | Level 11
Proc format;
   invalue resi
   'POS'=1
   'NEG'=0;
   value resv
   1='POS'
   0='NEG';
run;

data have;
input id test:$4. result $;
resn=input(result,resi.);
datalines;
1 GCCX NEG
1 GCCXO NEG
1 GCCX POS
2 GCCX NEG
3 GCCXO POS
3 GCCXO NEG
3 GCCX NEG
4 GCCX NEG
5 GCCX POS
5 GCCX POS
;
proc summary nway data=have(drop=result);
   class id;
   id test;
   var resn;
   output out=want (drop=_:)
   max=result;
 run;
proc print;
   format result resv.;
run;

Untitled.png 

Ksharp
Super User
data have;
input id test $ result $;
datalines;
1 GCCX NEG
1 GCCXO NEG
1 GCCX POS
2 GCCX NEG
3 GCCXO POS
3 GCCXO NEG
3 GCCX NEG
4 GCCX NEG
5 GCCX POS
5 GCCX POS
;

proc sql;
select id,min(test) as test,ifc(sum(result='POS'),'POS','NEG') as want
 from have
  group by id;
quit;

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1056 views
  • 1 like
  • 4 in conversation