BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
The phyid's have flag 'C' or 'P'. How do to display phyid that have flag 'C' and 'P'.

for instance:

Phyid flag
1001 C
1002 P
1003 C
1003 P
1004 C
1004 P

display only 1003 and 1004 as they have flag 'C' and 'P'.
8 REPLIES 8
RickM
Fluorite | Level 6
If flag can only have those two values then you could sort by phyid and flag. Then use by group processing with first.flag and last.flag to exclude observations that are both first and last within a group.
SASPhile
Quartz | Level 8
Thanks.
Phyid flag
1001 C
1002 P
1003 C
1003 P
1004 C
1004 P

if a phyid has C and P and we need only P to be displayed like 1003 and 1004 only P are displayed.
1001 C
1002 P
1003 P
1004 P
Cynthia_sas
SAS Super FREQ
Hi:
Do you want an output dataset or do you want a report??? And if you want a report, what is your destination of interest? If you want a dataset, do you just want to drop the obs for the phyid that has both C and P???
cynthia
SASPhile
Quartz | Level 8
Need dataset.If a phyid has a flag 'C' and 'P' i need only that record for 'P'.
1001 C
1002 P
1003 C
1003 P
1004 P
1004 C

the output:
1001 C
1002 P
1003 P
1004 P
RickM
Fluorite | Level 6
You could do this with two sorts. The first sort by phyid and descending flag. The second sort just by phyid and use the nodupkey option.
polingjw
Quartz | Level 8
[pre]

data test;
input phyid flag $;
datalines;
1001 C
1002 P
1003 C
1003 P
1004 C
1004 P
;
run;

proc sql;
select phyid from test where flag = 'C'
intersect
select phyid from test where flag = 'P';
quit;

[/pre]
chang_y_chung_hotmail_com
Obsidian | Level 7
@polingjw: Here is another way, taking advantage of proc sql's automatic re-merging of the summary statistics:
[pre]
/* test data by polingjw */
data test;
input phyid flag $;
datalines;
1001 C
1002 P
1003 C
1003 P
1004 C
1004 P
;
run;

proc sql;
create table test2 as
select phyid, flag, sum(flag="C") as c, sum(flag="P") as p
from test
group by phyid;

/* print out an obs if the id has only C or P;
the flag="P" obs if the id has both */
select * from test2
where (c and not p) or (not c and p) or (c and p and flag="P");
/* on lst
phyid flag c p
--------------------------------------
1001 C 1 0
1002 P 0 1
1003 P 1 1
1004 P 1 1
*/
quit;
[/pre]
SASPhile
Quartz | Level 8
This is interesting.Thanks for the help.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 8 replies
  • 1548 views
  • 0 likes
  • 5 in conversation