BookmarkSubscribeRSS Feed
L_L
Calcite | Level 5 L_L
Calcite | Level 5

Dear all

In attachment you will find an extract of the input datasets.

I have to summarize data about therapies as in the table below:

Total patients
Level1Level2N (%)
CardiacName1   xx(xx%)
Name2xx(xx%)
...xx(xx%)
...
Total patientsxx(100%)

The percentages are to be calculated on the basis of total patient and a patient could have more than one therapy.

Could you suggest a simple method of programming?

Thank you in advance

Regards

1 REPLY 1
jim_cai
Calcite | Level 5

could be something like:

 

proc import datafile='sasc.xls' out=sasc_in dbms=excel replace;
   sheet="foglio1$"; getnames=yes; mixed=yes; scantext=yes;
quit;

proc sql noprint;
   * Denominator: Subject Count in Total;
   select distinct n(distinct pt_id) into :pt_n from sasc_in
   where pt_id is not null;
quit;

%let pt_n=%left(%trim(&pt_n));

proc transpose out=sasc_tr( where=(upcase(_name_) not in('_' 'PT_ID') and col1^=''));
   var _all_; by pt_id;
quit;

data sasc_name;
   set;
   array name[*] $32. therapy level;
   drop i _:;
   do i=1 to dim(name);
      name[i] = scan(_name_, i, '_');
   end;
run;

proc sort; by pt_id therapy level;
quit;

* Level-1 and Level-2 per Patient per Therapy;
data sasc;
   merge sasc_name( in=_l1 where=(upcase(level)='LEVEL1') rename=(col1=level1))
         sasc_name( in=_l2 where=(upcase(level)='LEVEL2') rename=(col1=level2));
   by pt_id therapy;
   drop level;
   * Each Level Combination;
   level_n =1; output;
   * Total;
   level_n =2;
   level1 = "Total";
   level2 = "";
   therapy = ""; output;
run;

proc sort noduprecs; by level_n level1 level2 pt_id therapy;
quit;

* Subject Count per Combination of Levels;
proc freq noprint;
   by level_n level1;
   table level2/out=sasc_freq( drop=percent) sparse;
quit;

* Percentages;
data sasc_pct;
   set;
   n_pct = put(count, 2.)||' ('||put(100*count/&pt_n, 5.1)||'%)';
run;

 

just not sure how "simple" you consider it.

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
  • 1 reply
  • 844 views
  • 0 likes
  • 2 in conversation