DATA Step, Macro, Functions and more

Patients flagging question

Reply
N/A
Posts: 0

Patients flagging question

Howdy everyone

Just wondering if anyone can help me with this problem

Pat_id ST-JO NEPEA PRINC WESTM
1 1 . . .
2 1 . 1 .
3 . . . 1
4 . 1 . .
5 1 . 1 1
6 . 1 1 .
7 . . . 1
8 . 1 . 1
9 . 1 . .
10 1 . . .
11 . 1 . .
12 1 . . .
13 . 1 . .
14 . . 1 .
15 1 1 1 .

I'm interested in having a solution like the data set below

Pat_id only_at_St_John only_at_Nepean only_at_PRINC only_at_WESTM
1 ONLY VISITED NEVER VISITED NEVER VISITED NEVER VISITED
2 MULTI MULTI MULTI
MULTI
3 NEVER VISITED NEVER VISITED NEVER VISITED ONLY VISITED
4 NEVER VISITED ONLY VISITED NEVER VISITED NEVER VISITED
5 MULTI MULTI MULTI
MULTI
6 MULTI MULTI MULTI
MULTI
7 NEVER VISITED NEVER VISITED NEVER VISITED ONLY VISITED
8 MULTI MULTI MULTI
MULTI
9 NEVER VISITED ONLY VISITED NEVER VISITED NEVER VISITED
10 ONLY VISITED NEVER VISITED NEVER VISITED NEVER VISITED
11 NEVER VISITED ONLY VISITED NEVER VISITED NEVER VISITED
12 ONLY VISITED NEVER VISITED NEVER VISITED NEVER VISITED
13 NEVER VISITED ONLY VISITED NEVER VISITED NEVER VISITED
14 NEVER VISITED NEVER VISITED ONLY VISITED NEVER VISITED
15 MULTI MULTI MULTI
MULTI

Thank you Message was edited by: DonaldH
Valued Guide
Posts: 2,177

Re: Patients flagging question

Posted in reply to deleted_user
PROC FORMAT ;
*creating a translation from missing and 1 to visits string; [pre] value visits
1 ='ONLY VISITED'
. = 'NEVER VISITED'
2-high = 'MULTI' ;
run ;
proc print data= your_data ;
id Pat_id ;
format _numeric_ visits. pat_id best8. ;
run ; [/pre]
PeterC Sorry I misunderstood!
If more than one location, then all MULTI
So I've provided the wrong solution.... better later


Message was edited by: Peter.C
Super Contributor
Posts: 359

Re: Patients flagging question

Peter's solution will work if you first multiply each value by the sum of all of them.

ie. ST-Jo = st-JO * sum(ST-JO, NEPEA, PRINC, WESTM)
Valued Guide
Posts: 2,177

Re: Patients flagging question

alternately, apply this transform to the attendance record
(add rather than multiply)
array thos(*) ST-JO NEPEA PRINC WESTM ;
if n( of thos(*) ) >1 then do _i_=1 to dim(thos) ;
thos(i) +2 ;
end ;
that allows those that were attended, still to be distinguished.

and follow up with the print subject to the formatting

PeterC
N/A
Posts: 0

Re: Patients flagging question

My apology Peter but I can't quite figure out how to implement your solution in my code, do I apply the format to the array thos?
Valued Guide
Posts: 2,177

Re: Patients flagging question

Posted in reply to deleted_user
you can apply formats to variables, but not arraynames.
proc print data= your_updated_data ;
id Pat_id ;
format ST_JO NEPEA PRINC WESTM visits. ;
run ;
N/A
Posts: 0

Re: Patients flagging question

Hi Peter I did what you suggested but the 'MULTI' records did not come out quite right, did I do anything wrong here?
Valued Guide
Posts: 2,177

Re: Patients flagging question

Posted in reply to deleted_user
Donald H
I can almost debug blind ;-), but sas logs help

Would you like me to guess(see below), or provide your versions ........>

1 > provide : a sas-code showing what doesn't work
+
2 > provide : the sas-log showing what the sas system thought of the code,
+
3 > provide : the output, if any

PeterC








data orig ;
input Pat_id ST_JO NEPEA PRINC WESTM ;
list;cards;
1 1 . . .
2 1 . 1 .
3 . . . 1
4 . 1 . .
5 1 . 1 1
6 . 1 1 .
7 . . . 1
8 . 1 . 1
9 . 1 . .
10 1 . . .
11 . 1 . .
12 1 . . .
13 . 1 . .
14 . . 1 .
15 1 1 1 .
;

PROC FORMAT ;
*creating a translation from missing and 1 to visits string;
value visits
1 ='ONLY VISITED'
. = 'NEVER VISITED'
2-high = 'MULTI' ;
run ;
proc print data= orig ;
id Pat_id ;
format _numeric_ visits. pat_id best8. ;
run ;
data your_updated_data ;
set ;
array thos(*) ST_JO NEPEA PRINC WESTM ;
if n( of thos(*) ) >1 then
do _i_=1 to dim(thos) ;
thos(_i_) +2 ;
end ;
format ST_JO NEPEA PRINC WESTM visits. ;
run ;
proc print ;
run ; Message was edited by: Peter.C
Contributor
Posts: 24

Re: Patients flagging question

Posted in reply to deleted_user
PROC FORMAT ;
value visits
1 ='ONLY VISITED'
. = 'NEVER VISITED' ;
run ;


data newdata;
set yourdata;
drop i;
array thos(4) ST_JO NEPEA PRINC WESTM;
array new(4) $14. only_at_St_John only_at_Nepean only_at_PRINC only_at_WESTM;
if n( of org(*) ) >1 then do i=1 to 4;
new(i)="MULTI";
end;
else do i=1 to 4;
new(i)=put(org(i),visits.);
end;
run;
Ask a Question
Discussion stats
  • 8 replies
  • 155 views
  • 0 likes
  • 4 in conversation