For example I have this:
id test1 test2 test3 test4
123 NAATG NAATP HIV GRMS
321 NAATR NAATU
145 NAATR HCG
541 NAATP NAATR
654 NAATG NAATP HIV
658 NAATP NAATR
and so on
i would like to find any NAAT test. by id. I don't want to get only one NAAT test. For example; ID 654 has two NAAT tests, but I only want one test by ID. Need your help please.
This is where the guidance on posting a good question come in handy. From what you post, my answer would be:
data want; set have; keep id test1; run;
Then you will have one NAAT per id. I doubt that is what you want, but I have no other idea what you are talking about. Post what you expect out, clarify what the issue is, and post test data in the form of a datastep.
Thank you. I have about 5131 observations of those 3438 are male and i am trying to find how many male has any kind of NAAT test. same person (id) has more than one NAAT test but i just want any NAAT test by male.
You don't show a sex variable in your data set, so assuming one exists, you would just run a proc freq on the resulting table from my previous answer.
proc freq data=want;
table sex*flag / out=NAAT_by_Sex;
run;
You can use FIND()/INDEX() to see if the string contains the values NAAT.
You would use an array to loop over the strings and indicate if there was a NAAT value.
*sample data - please provide data in this format in future posts;
data have;
infile cards truncover;
input id (test1-test4) ($);
cards;
123 NAATG NAATP HIV GRMS
321 NAATR NAATU
145 HCG NAATR
541 NAATP NAATR
654 NAATG NAATP HIV
658 NAATP NAATR
;
run;
data want;
set have;
*declare array of variables to loop over;
array test(*) $ test1-test4;
*set flag to 0 as default;
flag=0;
*loop control;
do index=1 to dim(test) while (flag=0); *do until found value;
if find(test(index), 'NAAT')>0 then flag=1;
end;
run;
@Dhana18 wrote:
For example I have this:
id test1 test2 test3 test4
123 NAATG NAATP HIV GRMS
321 NAATR NAATU
145 NAATR HCG
541 NAATP NAATR
654 NAATG NAATP HIV
658 NAATP NAATR
and so on
i would like to find any NAAT test. by id. I don't want to get only one NAAT test. For example; ID 654 has two NAAT tests, but I only want one test by ID. Need your help please.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.