BookmarkSubscribeRSS Feed
lele619111
Calcite | Level 5

Hello- this is my first post in this community and hoping for some help, if I need to adjust anything about my style of posting, please let me know and I will adjust!
I am working with a healthcare dataset that involves many variables (some char, some numeric) that represent checkboxes in a database. 


For example, one would tick off all the applicable options to capture what outcome a patient may have ( 1 being Admitted, 2 being Discharged, etc.).
I am trying to produce simple frequency counts for each option ( 406 patients were Admitted, 189 patients were Discharged etc. ) and have made formats to convert each number into the corresponding character string.


However, observations that have more than one option chosen don't apply the format (if a patient was Transferred then Discharged, and both options were chosen, outputs as '2,5' not 'Transferred,Discharged'). I was thinking of using PRXMATCH to pick up instances of each number and creating secondary accumulating variables for each option, but am not sure thats most efficient . I've attached screenshots of the resulting frequency tables, and copy & pasted my code. Any guidance would be appreciated!

 

/***************************************************/


proc format;
value $status 1='Admitted' 2='Discharged'
3='Transferred' 4='Left AMA' 5='Expired'
6='Unknown' 7='Eloped';
run;


proc freq data=nonfatal.final;
format status_ednf_nnf1 $status.;
tables status_ednf_nnf1;
run;

 

/*******************************/

 

lele619111_1-1657052184158.png

lele619111_2-1657052197773.png

 

3 REPLIES 3
Reeza
Super User

You need to convert them before you concatenate them. 

Unfortunately there isn't a concatenation operator which handles this, so you need to loop through via an array. 

 

 

 

 

kleelasiva9
Obsidian | Level 7

By using tranwrd function, we can get the results in desired way. Please follow below code.

data sam;
length x $10;
x="1";output;
x="2,3";output;
x="1,3";output;
x="2";output;
x="1,2,3";output;
x="1,3";output;
x="2,3";output;
x="3";output;
; 
run;

data fin;
length word $100;
set sam;
word=x;
word=tranwrd(word,"1","Admitted");
word=tranwrd(word,"2","Treated");
word=tranwrd(word,"3","Discharged");
run;
ghosh
Barite | Level 11

Used the first part of your data to demo the process I would take to label the checkbox values

data have;
	length chks $ 10;
	input chks $;
	datalines;
1,2
1
1,2,3
1,2,4
1,3
1,4
1,4,3
1,5
2
2,3
2,4
2,5
2,6
;
proc format;
	value $status 1='Admitted' 2='Discharged' 
				  3='Transferred' 4='Left AMA' 
				  5='Expired' 6='Unknown' 7='Eloped';
run;

data want;
	set have;
	length parse $12 status_ednf_nnf1  $500;

	do i=1 by 1 until (parse='');
		parse=put(scan(chks, i, ','),$status.);

		if i=1 then
			status_ednf_nnf1=parse;
		else
			status_ednf_nnf1=catx(',', status_ednf_nnf1, parse);
	end;
	keep chks status_ednf_nnf1 ;
run;
proc print;
run;

ghosh_0-1657731378953.png

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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