BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

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. 

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Dhana18
Obsidian | Level 7

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. 

Reeza
Super User

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;
Reeza
Super User

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. 



 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 632 views
  • 0 likes
  • 3 in conversation