BookmarkSubscribeRSS Feed
sitaram
Calcite | Level 5

i have two datasets. 1. dum1 2. all_freqs

data dum1;length btoxgr $7.;
btoxgr='Grade 0'; output;
btoxgr='Grade 1'; output;
btoxgr='Grade 2'; output;
btoxgr='Grade 3'; output;
btoxgr='Grade 4'; output;
btoxgr='T_Btoxg'; output;
run;

 

data all_freqs;
PARCAT3='HAEMATOLOGY';btoxgr='Grade0';TRT01A='LZA';PARAMCD='GRAN';cnt=12;output;
PARCAT3='HAEMATOLOGY';btoxgr='Grade2';TRT01A='LZA';PARAMCD='GRAN';cnt=20;output;
PARCAT3='HAEMATOLOGY';btoxgr='Grade1';TRT01A='LZA';PARAMCD='LYMP';cnt=19;output;
PARCAT3='HAEMATOLOGY';btoxgr='Grade2';TRT01A='LZA';PARAMCD='KKSP';cnt=90;output;

PARCAT3='LIVER AND KIDNEY';btoxgr='Grade0';TRT01A='LZA';PARAMCD='PLAT';cnt=12;output;
PARCAT3='LIVER AND KIDNEY';btoxgr='Grade2';TRT01A='LZA';PARAMCD='WBC';cnt=22;output;
PARCAT3='LIVER AND KIDNEY';btoxgr='Grade1';TRT01A='LZA';PARAMCD='WBC';cnt=24;output;
PARCAT3='LIVER AND KIDNEY';btoxgr='Grade3';TRT01A='LZA';PARAMCD='AST';cnt=11;output;
run;

 

I would need a dataset that can take all the rows of  all_freqs merged with dum1 in all possible combination i.e. in all_freqs dataset under 1 parmcd we have btoxgr='Grade0' present only, in that case all other grades must be coming for the same paramcd with values 0 in cnt variable.

 

tried using the below code, but nor working.

data dummy; 
merge all_freqs(KEEP=parcat3 param paramcd trt01an trt01a btoxgr IN=A) dum1(in=b); */
BY BTOXGR;if a or b; 
RUN;

 

any help?

2 REPLIES 2
mkeintz
PROC Star

I do not understand what you want the output to look like.  Please show what it would look like for the sample data you have provided.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
data_null__
Jade | Level 19

How about a multlabel format.

 

data all_freqs;
PARCAT3='HAEMATOLOGY';btoxgr='Grade0';TRT01A='LZA';PARAMCD='GRAN';cnt=12;output;
PARCAT3='HAEMATOLOGY';btoxgr='Grade2';TRT01A='LZA';PARAMCD='GRAN';cnt=20;output;
PARCAT3='HAEMATOLOGY';btoxgr='Grade1';TRT01A='LZA';PARAMCD='LYMP';cnt=19;output;
PARCAT3='HAEMATOLOGY';btoxgr='Grade2';TRT01A='LZA';PARAMCD='KKSP';cnt=90;output;

PARCAT3='LIVER AND KIDNEY';btoxgr='Grade0';TRT01A='LZA';PARAMCD='PLAT';cnt=12;output;
PARCAT3='LIVER AND KIDNEY';btoxgr='Grade2';TRT01A='LZA';PARAMCD='WBC';cnt=22;output;
PARCAT3='LIVER AND KIDNEY';btoxgr='Grade1';TRT01A='LZA';PARAMCD='WBC';cnt=24;output;
PARCAT3='LIVER AND KIDNEY';btoxgr='Grade3';TRT01A='LZA';PARAMCD='AST';cnt=11;output;
run;
proc sort;
   by parcat3 paramcd trt01a;
   run;

proc format;
   value $txg(notsorted multilabel)
      'Grade0' = 'Grade 0'
      'Grade1' = 'Grade 1'
      'Grade2' = 'Grade 2'
      'Grade3' = 'Grade 3'
      'Grade4' = 'Grade 4'
      'Grade0'-'Grade4' = 'Total'
      ;
   quit;

proc summary data=all_freqs nway missing completetypes;
   by parcat3 paramcd trt01a;
   class btoxgr / mlf order=data preloadfmt;
   format btoxgr $txg.;
   freq cnt;
   output out=summary;
   run;
proc print;
   run;

Capture.PNG

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 366 views
  • 3 likes
  • 3 in conversation