BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
8 REPLIES 8
Peter_C
Rhodochrosite | Level 12
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
Flip
Fluorite | Level 6
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)
Peter_C
Rhodochrosite | Level 12
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
deleted_user
Not applicable
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?
Peter_C
Rhodochrosite | Level 12
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 ;
deleted_user
Not applicable
Hi Peter I did what you suggested but the 'MULTI' records did not come out quite right, did I do anything wrong here?
Peter_C
Rhodochrosite | Level 12
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
SUN59338
Obsidian | Level 7
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;

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
  • 8 replies
  • 885 views
  • 0 likes
  • 4 in conversation