BookmarkSubscribeRSS Feed
velango
Fluorite | Level 6

need to combine 2 datasets ANC & OTHER 

pull patient ids  who received both anc (supplies) and other (drug) in above 2 datasets

 

idcategorycategory desc
A11DRUG
A11DRUG
A13ANC
A13ANC
B11DRUG
C11DRUG
D11DRUG
F11DRUG
G11DRUG
G13ANC
G13ANC
G13ANC
G13ANC
G13ANC
H11 

 

i want id A& G  show up in the report

i used below code

data PTNT_both1 (keep= id categorycategory_desc) ;
merge ptnt_anc_out (in=anc) ptnt_other_out (in=other);
by patient_id;
if anc=1 and other=1;
run;

 not getting all records from A & G

 Please help

5 REPLIES 5
Kurt_Bremser
Super User

You talk about two datasets, but I only see a screen-copy of one. Please provide both datasets, and what you expect as a result out of them.

velango
Fluorite | Level 6

here are 2 datasets attached. i want to get patient id  with both category _id 11 & 13  with all records

Kurt_Bremser
Super User

These are not SAS datasets, these are Excel spreadsheets. Such files do not provide sufficient information about your variables.

This is the proper way to present example data, so that everyone can reliably work with it:

data ptnt_anc;
infile datalines dlm="|";
input PATIENT_ID :$5. ITEM_NAME :$30. DRUG_CATEGORY :$5. ITEM_CATEGORY_ID;
datalines;
194025|ALCOHOL PREP PADS (LRG)|ANC|13
194025|ALCOHOL ++ PREP PAD ST LRG|ANC|13
194025|UNDERPAD DURASOR 23"X36"|ANC|13
194025|SYRINGE 50-60ML L/L NO NEEDLE|ANC|13
317798|ALTERA HANDSET (NO COST)|OTH|13
329673|ALTERA HANDSET (NO COST)|OTH|13
;

data ptnt_other;
infile datalines dlm="|";
input PATIENT_ID :$5. ITEM_NAME :$30. DRUG_CATEGORY :$5. ITEM_CATEGORY_ID;
datalines;
194025|CUVITRU 20%|IGIV|11
194025|CUVITRU 20%|IGIV|11
303194|KISQALI B/P (TD 600MG/DY)|ONCOL|11
317798|CAYSTON INH SOLN|CF|11
317798|PULMOZYME INH SOLN|CF|11
329673|CAYSTON INH SOLN|CF|11
331633|PULMOZYME INH SOLN|CF|11
339601|TADALAFIL|PAH|11
;

Please run these codes and see if the resulting datasets match yours in terms of structure. Then provide the expected output.

Peter_L
Quartz | Level 8
Use SQL. It is far easier than the data step for such things. Use SELECT FROM and JOIN ON to do the work of MERGE if you want side-by-side columns or to select rows in one table based on rows in another. If you want stacked columns you might need also to use SELECT UNION later. I can't comment more as the question is not well enough defined (see other replies).
velango
Fluorite | Level 6

thank you. i tried SQL outer join . yes it is side by side

 i want them stacked. i will try select union  

thanks for your help

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1807 views
  • 0 likes
  • 3 in conversation