BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear

Some one from support helped me in the before. It worked for me until there is an obs I need to modify my code. Please help.

I highlighted in blue where i am getting wrong in results and code. How to exclude visit greater than '6' which is in character as cy9.

 

Thank you 

 

 

output  needed;

id      param        aval       visit            date

 1           bor         pr        cy6            2016-11-10

2           bor         sd           cy4           2016-08-02

3           bor         pr           cy5           2016-11-10

4           bor         cr           cy4           2016-08-02

5           bor         cr           cy4           2016-08-02

 

output getting

id      param        aval       visit            date

 1           bor         pr        cy6            2016-11-10

2           bor         sd           cy4           2016-08-02

3           bor         cr           cy9           2016-12-10

4           bor         cr           cy4           2016-08-02

5           bor         cr           cy4           2016-08-02


data ONE ;
  input ID TEST $ ORRES $ VISIT $ DATE $10.;
datalines;
1 ovrp sd cy5 2016-08-02 
1 ovrp pr cy6 2016-11-10
1 ovrp pd cy7 2016-12-10
2 ovrp sd cy4 2016-08-02 
2 ovrp pd cy5 2016-11-10
2 ovrp pd cy6 2016-11-10
3 ovrp sd cy4 2016-08-02 
3 ovrp pr cy5 2016-11-10
3 ovrp cr cy9 2016-12-10
4 ovrp cr cy4 2016-08-02 
4 ovrp pr cy5 2016-11-10
5 ovrp cr cy4 2016-08-02 
5 ovrp pr cy5 2016-11-10
5 ovrp sd dvs 2016-11-10
;
proc sort data=ONE out=SORTED(index=(ID_ORRES=(ID ORRES)));
  by ID DATE  VISIT;
run;
data TWO; 
  set SORTED;
  by ID;

  %* init;
  if first.ID then ID_DONE=0;
  if ID_DONE=0;
  ORDER=6-whichc(ORRES,'cr','pr','sd','pd','ne');
  output;

  if VISIT >='cy6' then do; "in my  code I used visit='cy6"
    ID_DONE+1;
    return;
  end;

  NEXTOBS=_N_+1;
  set SORTED(keep=ID ORRES rename=(ID=NEXT_ID ORRES=NEXT_ORRES) ) point=NEXTOBS;
  if ID=NEXT_ID and NEXT_ORRES='pd' then do;
    ID_DONE+1;
    return;
  end;
  keep ID TEST ORRES VISIT DATE ORDER;
run;
proc sql;
  create table THREE as 
  select ID, TEST, ORRES, VISIT, DATE
  from TWO
  group by ID
  having ORDER=max(ORDER);
quit;

 

10 REPLIES 10
PaigeMiller
Diamond | Level 26

6 is 'cy9'? 

 

Is that all you want to do is exclude where visit = 'cy9'?? Or is this a more general problem, in which case you haven't explained the problem at all.

 

You can exclude from any analysis 'cy9' with

 

set sorted(where=(visit^='cy9'));
--
Paige Miller
knveraraju91
Barite | Level 11

Thank you for quick reply. 

 

I will try to explain as much as I can.

 

In my code i highlighted in blue  "if VISIT='cy6' or "index(visit,'cy6') 
 condition gives me the output i need if subject has visit=cy6.

 

But for subject Id=3 does not have visit=cy6. He has visit=cy9 after cy4. 

 

so if I use "if VISIT='cy6' or "index(visit,'cy6') >0" it is picking up visit=cy9.

 

 

I am including my link to original post:

Thank you

https://communities.sas.com/t5/forums/replypage/board-id/programming/message-id/116548 

PaigeMiller
Diamond | Level 26

That's not the right link.

--
Paige Miller
PaigeMiller
Diamond | Level 26

I have looked at that thread, I really don't see a clear explanation in one place of what you want. Perhaps if I read every single comment and then combine them together in my mind, your requirements are clear, but really that's your job to make the requirements clear. So ... if you could, write a clear statement of the requirements you have ...

--
Paige Miller
knveraraju91
Barite | Level 11

Thank you very much for your time.

 

specs:

 

First I have to sort data by id date visit.
second by id, I have look until "orres='pd'" or up to visit='cy6'
which ever comes earlier

 

Of the all the "orres values" till either "orres='pd'" or up to visit='cy6'


I have to pick best "orres" value by following (cr>pr>sd>pd>ne).Which means if there is 'cr' at any visit prior to either


"orres='pd'" or up to visit='cy6' then i have to pick that 'cr' over others.

 

If there are no orres='pd' and visit='cy6' then I have to pick best observed value by following (cr>pr>sd>pd>ne)

 

With my code the issue is, if any subject(ex: id=3) does not have visit=cy6  then visits after visit='cy6'  (eg: 'cy9' is appearing in my output. Thank you

knveraraju91
Barite | Level 11

Hi

 

This sentence meaning

"If there are no orres='pd' and visit='cy6' then I have to pick best observed value by following (cr>pr>sd>pd>ne)"

 

assuming the patient discontinued before "visit=cy6"

knveraraju91
Barite | Level 11

Hi

 

This sentence meaning

"If there are no orres='pd' and visit='cy6' then I have to pick best observed value by following (cr>pr>sd>pd>ne)"

 

assuming the patient discontinued before "visit=cy6". If there is visit in (cy7  or cy8 or cy9) I should not pick these.

 

Thank you

ballardw
Super User

@knveraraju91 wrote:

Hi

 

This sentence meaning

"If there are no orres='pd' and visit='cy6' then I have to pick best observed value by following (cr>pr>sd>pd>ne)"

 

assuming the patient discontinued before "visit=cy6". If there is visit in (cy7  or cy8 or cy9) I should not pick these.

 

Thank you


Do these values of visit have ANY role in the selection process: (cy7  or cy8 or cy9).

If not then exclude them entirely such as:

proc sort data=ONE out=SORTED(index=(ID_ORRES=(ID ORRES)));
  where visit not in ('cy7' 'cy8' 'cy9');
  by ID DATE  VISIT;
run;

If they do play any role then the details need to be shared.

 

Reeza
Super User

@knveraraju91 It may help to link to your original question.

sas-innovate-2024.png

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.

 

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
  • 10 replies
  • 780 views
  • 1 like
  • 4 in conversation