DATA Step, Macro, Functions and more

Frequency analysis

Reply
Occasional Contributor
Posts: 5

Frequency analysis

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. 

Super User
Super User
Posts: 9,416

Re: Frequency analysis

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.

Occasional Contributor
Posts: 5

Re: Frequency analysis

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. 

Super User
Posts: 23,296

Re: Frequency analysis

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;
Super User
Posts: 23,296

Re: Frequency analysis

[ Edited ]

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. 



 

Ask a Question
Discussion stats
  • 4 replies
  • 52 views
  • 0 likes
  • 3 in conversation